You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a need to create a zod object schema that only has one key-value pair. This may not be exactly the best way to do something like this (and this is a contrived example), but in version 3.21.1, it was possible to assign the parsed data to the inferred type of a schema created through generic parameters:
import{z}from'zod';constcreateSchemaAndParse=<Kextendsstring,VSextendsz.ZodString>(key: K,valueSchema: VS,data: unknown)=>{constschema=z.object({[key]: vSchema});constparsed=schema.parse(data);constinferred: z.infer<z.ZodObject<{[kinK]: VS}>>=parsed;// this line errors in 3.21.2returninferred;};createSchemaAndParse('foo',z.string(),{foo: ''});
Unfortunately, with 3.21.2 (and above), the above line now produces a type error.
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I have a need to create a zod object schema that only has one key-value pair. This may not be exactly the best way to do something like this (and this is a contrived example), but in version 3.21.1, it was possible to assign the parsed data to the inferred type of a schema created through generic parameters:
Unfortunately, with 3.21.2 (and above), the above line now produces a type error.
The text was updated successfully, but these errors were encountered: