// this one is straightforward
const FileNode = Schema.TaggedStruct('file', {
content: Schema.Union(ProgramRef, RawData)
});
// following the example at https://effect.website/docs/schema/advanced-usage/#mutually-recursive-schemas
const DirNode = Schema.TaggedStruct('dir', {
children: Schema.Record({
key: Schema.NonEmptyString,
value: Schema.suspend((): Schema.Schema<fnode> => fnode)
})
});
const fields = {
name: Schema.NonEmptyString
};
// this extends from fields, but how do i also add the union? (the & (FileNode | DirNode) part)
interface FSNode extends Schema.Struct.Type<typeof fields> {
readonly parent: Option.Option<FSNode>;
}
// i've tried with extend
const FSNode = Schema.extend(
Schema.Struct({
...fields,
parent: Schema.OptionFromSelf(Schema.suspend((): Schema.Schema<fnode> => FSNode))
}),
// ...how do i add this?
Schema.Union(DirNode, FileNode)
);
// this one is straightforward
const FileNode = Schema.TaggedStruct('file', {
content: Schema.Union(ProgramRef, RawData)
});
// following the example at https://effect.website/docs/schema/advanced-usage/#mutually-recursive-schemas
const DirNode = Schema.TaggedStruct('dir', {
children: Schema.Record({
key: Schema.NonEmptyString,
value: Schema.suspend((): Schema.Schema<fnode> => fnode)
})
});
const fields = {
name: Schema.NonEmptyString
};
// this extends from fields, but how do i also add the union? (the & (FileNode | DirNode) part)
interface FSNode extends Schema.Struct.Type<typeof fields> {
readonly parent: Option.Option<FSNode>;
}
// i've tried with extend
const FSNode = Schema.extend(
Schema.Struct({
...fields,
parent: Schema.OptionFromSelf(Schema.suspend((): Schema.Schema<fnode> => FSNode))
}),
// ...how do i add this?
Schema.Union(DirNode, FileNode)
);