-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
4.7 circular type annotation regression #50688
Comments
It looks pretty circular to me. These types are too big and complex for us to investigate a root cause. If you can produce a small, standalone reproduction and convince yourself it should work, we can take a look. But definitely the library author is going to be in the best position to untangle this; sorry 😕 |
I believe I have a small repro for this issue as I encountered an identical situation. This works fine before 4.7 but after 4.7 it causes a circularity error. It appears to only cause an error whenever you check a constrained type parameter with a conditional type. I'm not sure whether a circularity error is the desired behavior here but I believe I was able to narrow the regression to #31455 |
For @typescript-bot: export {}
export interface Option<T> {
zip1<O extends Array<Option<any>>>(...others: O): Option<[T, ...UnzipOptionArray1<O>]>;
zip2<O extends Array<Option<any>>>(...others: O): Option<[T, ...UnzipOptionArray2<O>]>;
zip3<O extends Array<Option<any>>>(...others: O): Option<[T, ...UnzipOptionArray3<O>]>;
}
type UnzipOption<T> = T extends Option<infer V> ? V : never;
/// This doesn't work
type UnzipOptionArray1<T> = { [k in keyof T]: T[k] extends Option<any> ? UnzipOption<T[k]> : never };
/// But these work
type UnzipOptionArray2<T> = { [k in keyof T]: UnzipOption<T[k]> };
type UnzipOptionArray3<T> = { [k in keyof T]: T[k] extends Option<infer V> ? V : never };
declare const opt1: Option<number>;
declare const opt2: Option<string>;
declare const opt3: Option<boolean>;
const zipped1 = opt1.zip1(opt2, opt3);
const zipped2 = opt1.zip2(opt2, opt3);
const zipped3 = opt1.zip3(opt2, opt3); |
The change between v4.6.4 and v4.7.4 occurred at f76452c. |
@typescript-bot agrees. Thank you @Fireboltofdeath! |
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript. ❌ Failed: -
Historical Information
|
So unfortunately, trying out 4.9.4, while this error no longer appears, I do get this error that did not exist prior to 4.7: "error TS2589: Type instantiation is excessively deep and possibly infinite." Is this another regression or is there a way to work around this? |
Bug Report
🔎 Search Terms
"Return type annotation circularly references itself"
🕗 Version & Regression Information
The code works in 4.6.4 and stopped working when attempting to upgrade to 4.7+. I also verified the issue still appears in 4.8.X
⏯ Playground Link
https://github.com/davidmdm/myzod
Issue has been reported with davidmdm/myzod#52
Note that I am not the author of the linked library but rather a user. The author appears to be busy at the moment, so I was creating this ticket to see if the problem was a potential regression on the TypeScript side that could be fixed here instead if that is indeed the root cause.
💻 Code
https://github.com/davidmdm/myzod/blob/master/src/types.ts
🙁 Actual behavior
The code fails with the following errors
🙂 Expected behavior
The code compiles successfully.
The text was updated successfully, but these errors were encountered: