-
Notifications
You must be signed in to change notification settings - Fork 12.8k
"Number.isFinite" and "Number.isInteger" do not filter out values as a predicate #39090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
edit: I forgot type predicates are a thing, ignore the above brainfart. Note that the function doesn't work as a type predicate in general either: let x: number | null = 777 as any;
if (Number.isFinite(x)) {
x; // still number | null
} The fix would be for these functions to be declared as predicates, e.g. isFinite(number: unknown): number is number; |
Type guards are only correctly type guards if they return See #15048 for supporting type guards that only identify a subset of their type. |
Ah right, because otherwise |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.9.2
Search Terms: isFinite, isInteger, filter, callback, predicate, null values
Code
Expected behavior:
Actual behavior:
Playground Link:
https://www.typescriptlang.org/play/?ssl=2&ssc=7&pln=2&pc=21#code/MYewdgzgLgBGCuBbCMC8MDaBGANDATHgMx4IA2ZeArALoDcAsAFCiSwBmAlmVAKYBOvACYAxTmE580cJBAB0XHgIAUAOSQAjAXM4QxEvgEpGLcNBiK+goQEkwfAOYCU6BMgXcrazdt13HAsbMzKwQIGS8cmQgDsqWAsL6krxBppDhkdGx8db+vE78EKlAA
Related Issues: not found
The text was updated successfully, but these errors were encountered: