Skip to content

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

Closed
@svatal

Description

@svatal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions