Repository navigation
Replies: 2 comments
What do you mean by 'normally'?
Another way you can solve this problem: type TypedParseSchema<Schema extends z.ZodSchema> = Omit<Schema, 'parse'> & {
parse ( data: z.infer<Schema> ): z.infer<Schema>
}
const useTypedParse = <Schema extends z.ZodSchema>
( schema: Schema ): TypedParseSchema<Schema> => schema
const schemaWithTypedParse = useTypedParse( z.object( {
email: z.string(),
} ) )
schemaWithTypedParse.parse( 'hello' )
// ^^^^^^^
// Argument of type 'string' is not assignable to parameter of type '{ email: string; }'.Would this work for you? |
0 replies
|
This is now achievable with the new |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I didn't find someone having my issue so I'm probably doing something wrong but... I can't figure the solution out.
Let's say I have:
The last line will not throw an error with the Typescript whereas when hovering the parse function I can see:
Note that I use
strict: truein mytsconfig.json(and at runtime,zodthrows an error obviously).A "workaround" would be to always do this:
... but it's pretty verbose and annoying.
Any idea what's the issue to get the linter working normally?
Thank you,
EDIT: it seems a solution would be to use
(ref: #1748 (comment))
... but I don't get why this is not used by default?
All reactions