Closed as not planned
Closed as not planned
Description
TypeScript Version: 2.0.0
Code
// --strictNullChecks
interface IExample {
value?: number;
}
let example: IExample = {};
if (isFinite(example.value)) { // Accept possibly `undefined`
let a = example.value; // Narrow to `number`
}
Expected behavior:
- isFinite should accept
number | null | undefined
rather than strictlynumber
. - isFinite should act as a type guard.
Actual behavior:
Won't compile because isFinite
is not accepting undefined
and is not a type guard.
Proposal:
Change:
declare function isFinite(number: number): boolean;
To:
declare function isFinite(number: number | null | undefined): number is number;
I'm pretty sure there are other functions that could use the same love.
I don't mind putting in some hours if this is an accepted direction to take. Let me know :)