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
import{z}from'zod';import{Z}from'zod-class';enumColor{Red,Blue,Green,}enumColorAsString{Red='red',Blue='blue',Green='green',}constColorMap={[ColorAsString.Red]: Color.Red,[ColorAsString.Blue]: Color.Blue,[ColorAsString.Green]: Color.Green,}satisfiesRecord<ColorAsString,Color>;classCustomSchemaextendsZ.class({color: z.nativeEnum(ColorAsString).transform((c)=>ColorMap[c]),}){}// Works fine, but types are incorrectconsole.log(newCustomSchema({color: ColorAsString.Blue}));// Throws an exception because it parses twiceconsole.log(CustomSchema.parse({color: ColorAsString.Blue}));
The text was updated successfully, but these errors were encountered:
The problem occurs when
transform
has been used in the schema.I don't know what the intention was, but when parsing the schema,
zod class
performs double parsing. In theparse
function(https://github.com/sam-goodwin/zod-class/blob/main/src/index.ts#L305) and in the constructor(https://github.com/sam-goodwin/zod-class/blob/main/src/index.ts#L187).I think this is also an performance issue, because why would we parse the schema twice?
There is also a problem of types in constructor when we use
transform
fromzod
.Example code to reproduce problem:
https://stackblitz.com/edit/stackblitz-starters-cg4bsqz2?file=main.ts&view=editor
The text was updated successfully, but these errors were encountered: