Replies: 4 comments 3 replies
-
I am aware of this problem, but have not had time to investigate it in detail. Currently, the behavior you expect is not possible. Do you know how it is with other schema libraries? |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for the answer! Unfortunatelly, I am not aware of others implementation. |
Beta Was this translation helpful? Give feedback.
-
@sumerokr Here's a custom transform function, which takes an input type, an output schema, performs the transform, and validates only the output. export function ioTransform<TInput, TOutput extends BaseSchema>(
outputSchema: TOutput,
action: (value: TInput) => Output<TOutput>
): BaseSchema<TInput, Output<TOutput>> {
return {
...outputSchema,
_parse(input: TInput, info?: ParseInfo) {
return outputSchema._parse(action(input), info);
}
};
} It does require a custom validator to handle |
Beta Was this translation helpful? Give feedback.
-
Can we add this to the core library, I'm in very need of this to perform my validation to transform string to array string and validate that array |
Beta Was this translation helpful? Give feedback.
-
Hi,
How can I receive a
string
input, coerce it tonumber
, only then validate it as anumber
and also makeInput
andOutput
type correct?Or, in other words, how can I create a schema that
string
forInput<typeof MySchema>
string
value tonumber
type before validationnumber
number
valuenumber
forOutput<typeof MySchema>
What I have found in docs
While string can be passed here, its
Input<typeof NumberSchema>
returnsnumber
.Sets correct
Input
(string
) andOutput
(number
) types, but validation happens againststring
, before the transformation takes place.Beta Was this translation helpful? Give feedback.
All reactions