zod icon indicating copy to clipboard operation
zod copied to clipboard

Large declaration files for flattened zod schema

Open EllAchE opened this issue 1 year ago • 4 comments

luluNextData.txt

When emitting declaration files for a complex nested json the resulting declaration file can end up being quite large. I've shared a schema above generated from a large json (next data from a lululemon page) using https://transform.tools/typescript-to-zod. This results in a 17mb declaration file (.d.ts).

A quick look at the .d.ts file shows very large const declaraions of the the zod objects. Anything I can do to reduce this file size? If naively doing this as a human I could just modify the zod schema into an interface/type and avoid declaring the large consts, as the declaration files for inferred types don't need the zod context.

This is in a typescript project with the following tsconfig settings

{
  "compileOnSave": true,
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "composite": true,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "incremental": true,
    "lib": ["esnext"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noErrorTruncation": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext"
  }
}

EllAchE avatar May 07 '24 22:05 EllAchE

Thanks for this! I've replicated and work on this for Zod 4.

colinhacks avatar May 08 '24 18:05 colinhacks