Invalid declarations emitted when using ZodObject from zod as return type of generic function #54560
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Bug Report
🔎 Search Terms
zod, ZodObject, declaration, invalid declaration emit, extends infer T, union distribution, Type 'k' cannot be used to index type 'addQuestionMarks', skipLibCheck, error 2536, generic function return type
🕗 Version & Regression Information
Observed in all versions starting from 4.7. Tested on 4.7.4, 4.8.4, 4.9.5, 5.0.4, 5.1.3, 5.2.0-dev20230607. Works correctly on 4.6.4.
⏯ Playground Link
The playground contains relevant simplified type definitions from zod library in an attempt to produce a minimal reproducible example.
Playground link with relevant code
💻 Code
Ignore
({}) as any
, it is just to avoid writing function implementation.🙁 Actual behavior
Code gets compiled into the following declaration:
This declaration produces the following type error when copy-pasted back into TS playground:
🙂 Expected behavior
The generated declaration should be valid.
For example, this would be a valid declaration:
4.6.4 produces declaration without
extends infer T
which is also valid:Related issues:
Special thanks to @KaoSDlanor for posting an issue in the zod repo than inspired me to write this one and @pivstone for helping me with the investigation
The text was updated successfully, but these errors were encountered: