Skip to content

Narrowing via assignment in switch broken by #35000 #35070

Closed

Description

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

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions