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 am using zod to work with TypeScript enums and have encountered an issue when trying to retrieve the keys from an enum using z.nativeEnum. The z.nativeEnum function does not seem to provide a method to retrieve the keys of the enum, unlike the standard TypeScript keyof type operator.
Here's an example illustrating the issue:
// Definition of SomeEnum using TypeScriptenumSomeEnum{PNG=1,APNG=2,Lottie=3,GIF=4,};// Attempt to use keyof on SomeEnum directlytypeSomeEnumKeyof=keyoftypeofSomeEnum;// This works as expected// Using z.nativeEnum with SomeEnumconstSomeEnumSchema=z.nativeEnum(SomeEnum);// Attempting to use keyof on z.nativeEnum result// The following line throws an error because .keyof() method does not existconstkeySomeEnum=SomeEnumSchema.keyof();// This does not work
Could you provide guidance on how to properly retrieve the keys from an enum defined with z.nativeEnum? Is there a workaround or a method that I might be missing?
Thank you for your assistance, and apologies for any confusion caused by my language skills.
The text was updated successfully, but these errors were encountered:
Hello,
I am using zod to work with TypeScript enums and have encountered an issue when trying to retrieve the keys from an enum using
z.nativeEnum
. Thez.nativeEnum
function does not seem to provide a method to retrieve the keys of the enum, unlike the standard TypeScript keyof type operator.Here's an example illustrating the issue:
Could you provide guidance on how to properly retrieve the keys from an enum defined with
z.nativeEnum
? Is there a workaround or a method that I might be missing?Thank you for your assistance, and apologies for any confusion caused by my language skills.
The text was updated successfully, but these errors were encountered: