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

Evolving any ignores branches before a 'continue' #60945

Open
jared-hughes opened this issue Jan 9, 2025 · 1 comment
Open

Evolving any ignores branches before a 'continue' #60945

jared-hughes opened this issue Jan 9, 2025 · 1 comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@jared-hughes
Copy link

πŸ”Ž Search Terms

"evolving any", "implicit any", "for loop continue", "incorrect inference"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "evolving let"

⏯ Playground Link

Playground link with relevant code: https://www.typescriptlang.org/play/?ts=5.7.2#code/DYUwLgBAlgciAeYDcAoAZgewE4QBSkiggF4IAGJaCAHggEYKrTYEwBKCAbxQl4gHp+fYSNHCAegH4efKGjxFipAKwduY6HEQkIAcgBGAQwAmu1BoDGGAHZgo1gK4hzfAL4zeLbcwgBqeqiuQA

πŸ’» Code

let iNext;
for (let i = 0; i < 10; i = iNext) {
    //                      ^? let iNext: number
    if (i == 5) {
        iNext = 'bad';
        continue;
    }
    iNext = i + 1;
}

πŸ™ Actual behavior

The type of iNext is an evolving any. It evolved to number (at the point of i = iNext), which is incorrect because iNext = 'bad' can assign it a string. The assignment before continue doesn't get included in the type.

πŸ™‚ Expected behavior

The type of iNext should evolve to string | number as measured at i = iNext because either the assignment iNext = 'bad' or iNext = i + 1 are on a control flow path between let iNext and i = iNext.

This should give an error because i has type number.

Additional information about the issue

No response

@Andarist
Copy link
Contributor

Andarist commented Jan 9, 2025

The evolving any here is a red herring. The same thing happens with an annotated variable. It's some general issue with CFA: TS playground

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jan 9, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants