-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScript
Milestone
Description
1.8.10 / next (1.9.0-dev.20160414)
Code
export function X() {
let x: number | number[] = 0;
if (typeof x === "number") {
x; // ts.createProgram(...).getTypeChecker().getTypeAtLocation(Identifier::x).getFlags() --> number
const y = x; // ts.createProgram(...).getTypeChecker().getTypeAtLocation(Identifier::y).getFlags() --> number
}
if (typeof x !== "object") {
x; // ts.createProgram(...).getTypeChecker().getTypeAtLocation(Identifier::x).getFlags() --> number
const y = x; // ts.createProgram(...).getTypeChecker().getTypeAtLocation(Identifier::y).getFlags() --> number
}
if (!Array.isArray(x)) {
x; // ts.createProgram(...).getTypeChecker().getTypeAtLocation(Identifier::x).getFlags() --> Union
const y = x; // ts.createProgram(...).getTypeChecker().getTypeAtLocation(Identifier::y).getFlags() --> number
}Behavior:
Why does TypeChecker::getTypeAtLocation(Identifier::x) correctly report number after the first (typeof x === "number") & second (typeof x !== "object") type guards, but report the (un-narrowed) Union type after the third (!Array.isArray(x)) type guard? All three block's const c is correctly typed as number. Is there something besides TypeChecker::getTypeAtLocation(Identifier) to use here?
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptRelates to the public API for TypeScript