Type narrowing of string literal seems to get loosened in callbacks · Issue #14748 · microsoft/TypeScript (original) (raw)

TypeScript Version: 2.2.1

Code

function myValueArg(arg: "value") { }

function myStringArg(arg: string) { }

namespace ns { // Not needed, but shows it's not scope related let str = "value";

if (str === "value") {
    myValueArg(str);
    [].forEach(() => {
        myValueArg(str); // Argument of type 'string' is not assignable to parameter of type '"value"'.
    });
} else {
    myStringArg(str);
    [].forEach(() => {
        myStringArg(str);
    });
}

}

Expected behavior:
No warnings: the value (and type) of str has not changed.

Actual behavior:
Warning Argument of type 'string' is not assignable to parameter of type '"value"'.