A
arktype2w ago
Tom

can `optional()` be used with a thunk?

I want to do something like this (to allow null values to be ignored):
export const mod = scope({
Nested: {
something: "boolean",
},
Model: {
field: () => mod.type("Nested").or(type.null.pipe(() => undefined)).optional(),
other: "string",
},
});
export const mod = scope({
Nested: {
something: "boolean",
},
Model: {
field: () => mod.type("Nested").or(type.null.pipe(() => undefined)).optional(),
other: "string",
},
});
But I get the error: Type definitions must be strings or objects (was Function) I am needing to use a thunk because in my real case I am using a type defined within the scope. But maybe there's another way of achieving that?
4 Replies
ssalbdivad
ssalbdivad2w ago
Could you just use a normal optional key like "field?"
Tom
TomOP2w ago
yeah, sort of. I was doing that originally, but started getting An unordered union of a type including a morph and a type with overlapping input is indeterminate. But now I think about it, I suspect I would probably get the same issue even with .optional()?
ssalbdivad
ssalbdivad2w ago
Yeah they're functionally identical
Tom
TomOP2w ago
I haven't managed to reduce this down to a simple example yet, maybe I'll do that so I can understand what's going on

Did you find this page helpful?