Z
Zod8mo ago
Yamereee

Yamereee - Does anyone know how I can type this...

Does anyone know how I can type this using zod?
export const SOME_MAPPING = {
A1: ['AAA'],
A2: ['AAA', 'BBB'],
} as const;

export const SOME_MAPPING_ENUM = z.nativeEnum(SOME_MAPPING);
export const SOME_MAPPING = {
A1: ['AAA'],
A2: ['AAA', 'BBB'],
} as const;

export const SOME_MAPPING_ENUM = z.nativeEnum(SOME_MAPPING);
But I get the error:
Argument of type '{ readonly A1: readonly ["AAA"]; readonly A2: readonly ["AAA", "BBB"]; }' is not assignable to parameter of type 'EnumLike'.
Property 'A1' is incompatible with index signature.
Type 'readonly ["AAA"]' is not assignable to type 'string | number'.
Argument of type '{ readonly A1: readonly ["AAA"]; readonly A2: readonly ["AAA", "BBB"]; }' is not assignable to parameter of type 'EnumLike'.
Property 'A1' is incompatible with index signature.
Type 'readonly ["AAA"]' is not assignable to type 'string | number'.
1 Reply
Svish
Svish8mo ago
export const schema = z.object({
A1: z.enum(['AAA']),
A2: z.enum(['AAA', 'BBB'],
})
export const schema = z.object({
A1: z.enum(['AAA']),
A2: z.enum(['AAA', 'BBB'],
})
If you need to access the enum values, I think there's something along the lines of schema.A1.options(), or something
Want results from more Discord servers?
Add your server