Skip to content

Circular dependency check gets into way of perfectly valid type #51025

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

Closed
svatal opened this issue Oct 1, 2022 · 2 comments
Closed

Circular dependency check gets into way of perfectly valid type #51025

svatal opened this issue Oct 1, 2022 · 2 comments

Comments

@svatal
Copy link

svatal commented Oct 1, 2022

Bug Report

πŸ”Ž Search Terms

7022, circular

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

let a : {prop: string} | undefined = undefined;
for (let x=0; x<2; x++) {
  const dep = a === undefined ? "a" : "b";
  a = {prop: dep}
}

πŸ™ Actual behavior

'dep' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

If not inside any type of cycle (e.g. while (true)), dep is correctly typed as "a" | "b" (see the playground link). So the actual value of a has not been used in the type information. Even if it has been the case, the cycle should break because a.prop is strongly defined and is not dependant in any case on the a = {prop: dep} assignment

πŸ™‚ Expected behavior

dep typed as "a" | "b" even in the cycle

Similar issues

I've found few simillar issues (e.g. 49837), but not one as simple as this case.

@MartinJohns
Copy link
Contributor

Duplicate of #43047.

@svatal
Copy link
Author

svatal commented Oct 1, 2022

you are right, this one is quite similar, closing

@svatal svatal closed this as completed Oct 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants