Recursive type problem:

Hello, I'm trying to define a recursive type with the library, but without success, i have the error remoteFieldSchema is unresolvable. What can i do: const recTypes = type.module({ remoteFieldSchema: { arguments: type({ "[string]": "string" }), field: type({ "[string]": "remoteFieldSchema" }).optional(), }, }); thanks in advance.
2 Replies
ssalbdivad
ssalbdivad2w ago
Don't wrap your definitions in type- that will try to parse them using the default scope Just pass them directly to type.module and use "field?" to make the key optional I meant to add a gotcha about this to the Scope docs, so this is a good reminder thank you 🙂 Here's the new warning: Even if you reference it as part of your scope definition, the global type parser only knows about builtin keywords.
const badScope = scope({
id: "string",
// ❌ wrapping this definition in `type` will fail
badEntity: type({
// TypeScript: 'id' is unresolvable
id: "id"
}),
// ✅ reference scoped definitions directly instead of wrapping them
goodEntity: {
id: "id"
}
})
const badScope = scope({
id: "string",
// ❌ wrapping this definition in `type` will fail
badEntity: type({
// TypeScript: 'id' is unresolvable
id: "id"
}),
// ✅ reference scoped definitions directly instead of wrapping them
goodEntity: {
id: "id"
}
})
If you need access to fluent syntax from within a scope, see thunks.
papy0977
papy0977OP2w ago
Thank you very much !

Did you find this page helpful?