-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Generic schema builder compiles into invalid type definitions #2260
Comments
This is also an issue for us (cc @pivstone). We found a couple of seemingly relevant issues in the TS and zod repos:
The first two are fixed and released in TS 4.8, but we still experience the same issue in TS >= 4.8. The intention of I believe this is more of a TS issue. I have created a minimal reproduction example in TS Playground and submitted an issue in the TS repo: microsoft/TypeScript#54560 The culprit appears to be the combination of generic object-type transformation helpers. If I remove any one of them, then the compiled declaration does not have the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@mayorandrew You can work around the issue by setting the |
If you define a function which accepts a generic type parameter and returns a Zod object schema containing a string literal based on that type parameter then the code looks fine and typescript will compile it
The declaration file emitted is invalid though and cannot be imported into another project
Minimal reproduction:
./src/index.ts
When compiled will emit the following declaration file
./dist/index.d.ts
When imported this throws the errors:
I can't seem to find where the
extends infer T
is coming from on line 6 anywhere in the Zod code. Same goes for theextends infer T_1
on line 10Relevant configuration:
tsc
Additional information
If the generic function directly returns a Zod literal schema based on the passed generic then everything seems to work fine. Only putting that literal into an object seems to break the definition
The text was updated successfully, but these errors were encountered: