-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Context
When working with a schema containing transforms, it happens that the raw values types in the form don't match the schema.parse
return type. This is the case in the checkboxes example documented in the readme where the type of the "input" is undefined|string
and the resulting value is of type boolean
. This also happen when working with text inputs storing arrays of values for example:
<input type="text" value="value1,value2"/>
Problem
With the following schema:
const FormSchema = z.object({
myarray: z.string().transform(strValues => strValues.split(',')).pipe(z.array(z.string()))
})
The type of zo.fields.myarray
is generated from the parse output type (string[]
in that case). Which leads to the compiler not allowing to call zo.fields.myarray
without an index
argument:
<input type="text" name={zo.fields.myarray()/*Error: An argument for 'index' was not provided*/}value="value1,value2"/>
Solution
Changing this line so that the FieldChain is computed from the parse input instead of the parse result would fix this.
export declare type FieldChainFromSchema<T extends GenericSchema> = FieldChain<DeepNonNullable<z.input<T>>>;
The change should probably also be applied to the ErrorChainFromSchema
type.
I can make a PR if you want. :)