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
When using a function to omit shared keys among many schemas z.infer nolonger exports the underlying types correctly
import{z}from"zod";constmetaKeys={_rid: z.string(),_self: z.string(),_etag: z.string(),_attachments: z.string(),_ts: z.string(),};functionomitMetaKeys(schema: z.AnyZodObject): z.AnyZodObject{returnschema.merge(z.object({...metaKeys})).omit(Object.keys(metaKeys).reduce((prev,curr)=>{return{[curr]: true, ...prev}},{}));}exportconstmySchema=z.object({id: z.string(),});exportinterfacemyTypeextendsz.infer<typeofmySchema>{}// works correctly complaining about the missing id propertyconsteg:myType={}exportconstmyOmitSchema=omitMetaKeys(z.object({id: z.string(),}));exportinterfacemyOmitTypeextendsz.infer<typeofmyOmitSchema>{}//does not complain, whihc is incorrect behaviourconstegOmit:myOmitType={}
if we use the same schema and remove the call to omitMetaKeys, we gain typing within vscode
The text was updated successfully, but these errors were encountered:
Thanks this seems to be much closer, your code didn't seem to work for me, but the below did, however i am not sure how 'good' it is in comparison in terms of typescript correctness.
When using a function to omit shared keys among many schemas z.infer nolonger exports the underlying types correctly
if we use the same schema and remove the call to omitMetaKeys, we gain typing within vscode
The text was updated successfully, but these errors were encountered: