Skip to content

Type guard of Number.isNaN is wrong #12302

@saschanaz

Description

@saschanaz

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

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions