Skip to content

Narrowing via assignment in switch broken by #35000 #35070

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
sandersn opened this issue Nov 13, 2019 · 0 comments · Fixed by #35087
Closed

Narrowing via assignment in switch broken by #35000 #35070

sandersn opened this issue Nov 13, 2019 · 0 comments · Fixed by #35087
Assignees
Labels
Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

#35000 breaks activex-scripting on Definitely Typed because narrowing via assignment in switch no longer works:

type O = {
    a: number,
    b: number
}
type K = keyof O | 'c'
function f(o: O, k: K) {
    switch(k) {
        case 'c':
            k = 'a'
    }
    k === 'c' // should have error here
    return o[k] // and no error here
}

Actual behavior:
No error on k === 'c' and error on o[k].

Using if (k === 'c') { instead of switch (k) { case 'c': works correctly.

@sandersn sandersn added this to the TypeScript 3.8.0 milestone Nov 13, 2019
@sandersn sandersn added Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis labels Nov 13, 2019
@ahejlsberg ahejlsberg added the Fix Available A PR has been opened for this issue label Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants