Closed
Description
TypeScript Version: 3.8.0-dev.20191102
Search Terms: Number isInteger isSafeInteger isFinite isNaN
Code
declare function use(number: number): void;
declare const maybeNumber: string | number;
if (Number.isInteger(maybeNumber)) {
use(maybeNumber as number);
}
Expected behavior:
Type checks
Actual behavior:
Fails to type check because Number.isInteger
is typed to take only number
.
Related Issues:
- Fixes Number.is* signatures to accept any input. #24436 - PR that already addressed this 18 months ago, but seems to have been accidentally reverted by 2f73986.
- lib.d.ts contains wrong typings for Number.isFinite() #15527 - closed for housekeeping.
isNaN
andisFinite
should accept number or string #4002 - not the same issue - that issue is about the global functions that coerce their argument, while this is about the functions onNumber
that don't, making it safe to widen the accepted types.- Number.isInteger and others should accept any and act as type guards #21199 - a broader issue, since it's currently infeasible to make these type guards.