-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Tried my hardest to find if this was a duplicate error, so sorry if it is.
{
let foo: string | number;
if (typeof foo === "string") {
throw "end";
}
foo; //Should Be: number; Is: number; Correct
}
In the code snippet above, it's correct that after the if statement, foo should be narrowed to type number, because if it is type string, then an error is thrown. However if abstracting the throw statement away into a function whose return type is never, the narrowing does not occur.
{
let end = function(): never {
throw "end";
}
let foo: string | number;
if (typeof foo === "string") {
end();
}
foo; //Should Be: number; Is: string | number; Incorrect
}
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created