Closed
Description
TypeScript Version: 2.1 RC bundled in VS2017 RC
Code
let num = 8;
if (!Number.isNaN(num)) { // NumberConstructor.isNaN(value: any): value is number
printNumber(num + 1); // `num` should still be a number but TS thinks it has `never` type
}
function printNumber(num: number) {
console.log(`Got ${num} - 1`);
}
Expected behavior: No error
Actual behavior: TS2356 An arithmetic operand must be of type 'any', 'number' or an enum type.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
akarzazi commentedon Nov 16, 2016
This code would raise an other error on
num++
since it was declared withconst
.Javascript :
VM173:2 Uncaught TypeError: Assignment to constant variable
RyanCavanaugh commentedon Nov 17, 2016
Introduced via #11670. Seemed like a good idea at the time!