Skip to content
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

Closed
DavidRigglemanININ opened this issue Sep 8, 2022 · 7 comments · Fixed by #51151
Closed

4.7 circular type annotation regression #50688

DavidRigglemanININ opened this issue Sep 8, 2022 · 7 comments · Fixed by #51151
Assignees
Labels
Fix Available A PR has been opened for this issue Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros Needs Investigation This issue needs a team member to investigate its status.

Comments

@DavidRigglemanININ
Copy link

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

  • This changed between versions 4.6.4 and 4.7

⏯ 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

node_modules/myzod/libs/types.d.ts:256:40 - error TS2577: Return type annotation circularly references itself.

256     and<K extends AnyType>(schema: K): IntersectionResult<this, K>;
                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/myzod/libs/types.d.ts:306:40 - error TS2577: Return type annotation circularly references itself.

306     and<K extends AnyType>(schema: K): IntersectionResult<this, K>;

🙂 Expected behavior

The code compiles successfully.

@andrewbranch
Copy link
Member

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 😕

@andrewbranch andrewbranch added the Needs More Info The issue still hasn't been fully clarified label Sep 9, 2022
@Fireboltofdeath
Copy link

Fireboltofdeath commented Sep 29, 2022

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

Playground

@andrewbranch
Copy link
Member

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);

@typescript-bot typescript-bot added the Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros label Sep 29, 2022
@typescript-bot
Copy link
Collaborator

The change between v4.6.4 and v4.7.4 occurred at f76452c.

@andrewbranch
Copy link
Member

@typescript-bot agrees. Thank you @Fireboltofdeath!

@andrewbranch andrewbranch added Needs Investigation This issue needs a team member to investigate its status. and removed Needs More Info The issue still hasn't been fully clarified labels Sep 29, 2022
@andrewbranch andrewbranch added this to the TypeScript 4.9.0 milestone Sep 29, 2022
@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 30, 2022

👋 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.


Comment by @andrewbranch

❌ Failed: -

  • Return type annotation circularly references itself.

Historical Information
Version Reproduction Outputs
4.7.2, 4.8.2

❌ Failed: -

  • Return type annotation circularly references itself.

4.4.2, 4.5.2, 4.6.2

👍 Compiled

@andrewbranch andrewbranch changed the title Typing issues in 4.7+ 4.7 circular type annotation regression Sep 30, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Oct 12, 2022
@DavidRigglemanININ
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
5 participants