-
-
Notifications
You must be signed in to change notification settings - Fork 496
#2210: Support typescript isolated declarations in ZOD #2539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Typescript: Support --isolatedDeclarations
Typescript: Support --isolatedDeclarations
update samples
Added support for "as const satisfies readonly"
fix samples
|
Also added Additional Enhancement:
|
fix samples
|
Looks like tests are failing? |
Add TypeScript
isolatedDeclarationssupport for Zod moduleOverview
This PR adds full support for TypeScript's
isolatedDeclarationscompiler option in the Zod module. This ensures that generated Zod schemas and related code are compatible with TypeScript's isolated declaration files feature, which requires explicit type annotations for all exported variables and functions.Changes
isolatedDeclarations:RegExpconstants:: RegExpmin,max,multipleOf,exclusiveMin,exclusiveMax):: numberstring,number,boolean,Date,Record<string, unknown>,unknown[],readonly unknown[])Configuration Updates
isolatedDeclarationsin TypeScript configs: AddedisolatedDeclarations: trueto:packages/zod/tsconfig.jsonpackages/zod/tsconfig.build.jsontests/tsconfig.jsontests/configs/zod.config.ts(addedtsconfigreference to all output configurations)Test Updates
stripNillfunction intests/mutators/zod-preprocess.tsto include explicit return type annotationWhy This Change?
TypeScript's
isolatedDeclarationsfeature ensures that.d.tsfiles can be generated independently without analyzing the implementation files. This improves build performance and enables better tooling support. However, it requires explicit type annotations for:By adding these annotations, we ensure that generated Zod schemas work seamlessly with projects that have
isolatedDeclarationsenabled, which is becoming a common requirement in modern TypeScript projects.Testing
isolatedDeclarations: trueBackward Compatibility
This change is fully backward compatible. The generated code still works in projects without
isolatedDeclarationsenabled, and the functionality remains unchanged. The only difference is the addition of explicit type annotations, which is a TypeScript best practice regardless of theisolatedDeclarationssetting.