Closed jansedlon closed 1 month ago
Thank you for creating this issue, I will try to find a solution soon!
This should be fixed now! Thank you!
@fabian-hiller Thank YOU for the wonderful work you're doing 🙏 One question, i updated the package and tried it again. Should it really infer to undefined if there's a provided default value?
Why am i insisting on it so much? I'm using @conform-to/react
library for Form handling in Remix.run framework and it returns available functions based on return type of a given schema. Since it infers the type as the type or undefined, I don't have access to array methods.
PS: For now the workaround is this
// Infer the type of the inner schema
type ResourceSchemaData = InferOutput<typeof ResourceSchema>
// Cast the default value
resources: optional(array(ResourceSchema), [] as ResourceSchemaData[])
What's the difference?
Given simple example
const a = optional(array(string()), []);
The type of the default parameter is inferred as
Default<ArraySchema<StringSchema<undefined>, undefined>, undefined>
but when the default parameter is casted as as string[]
, the type for the default parameter is string[]
and not the previous one
You are right, there is still a problem with empty arrays as default argument. I will fix it in the next few minutes and release another version. Thanks for your feedback!
Should be fixed now. You can check it in our playground.
Works great, thank you
Given this schema
The
resources
type is inferred as never or the type. It shouldn't really be never. I'm on version 0.31