Skip to content

Number check functions such as isNaN shouldn't constrain their parameter type #16427

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

Closed
falsandtru opened this issue Jun 9, 2017 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Jun 9, 2017

TypeScript Version: master

Code

isNaN(<any>null); // should be able to pass any value without type casting

Expected behavior:

declare function isNaN(target: any): boolean;

Actual behavior:

declare function isNaN(number: number): boolean;
@falsandtru falsandtru changed the title Number check functions such as isNaN shouldn't have parameter type constraints Number check functions in the Number variable such as isNaN shouldn't have parameter type constraints as with global isNaN Jun 9, 2017
@falsandtru falsandtru changed the title Number check functions in the Number variable such as isNaN shouldn't have parameter type constraints as with global isNaN Number check functions in the Number variable such as isNaN shouldn't constrain their parameter type as with global isNaN Jun 10, 2017
@ghost
Copy link

ghost commented Jun 10, 2017

While code like Number.isNaN("foo") technically won't crash, it won't accomplish anything either.
We also have errors for new Set<string>().has(0); and /rgx/.test(0);.

@falsandtru
Copy link
Contributor Author

For example, when we write compare function also working with NaN, we need the exact function detecting NaN.

var a: number | string = '';
[''].findIndex(b => a === b || Number.isNaN(a) && Number.isNaN(b));

I believe this code should be accepted.

@falsandtru
Copy link
Contributor Author

Sorry, I found global isNaN also constrains the parameter type. So I fix the code to:

var a: number | string = '';
[''].findIndex(b => a === b || isNaN(a) && isNaN(b));

@falsandtru falsandtru changed the title Number check functions in the Number variable such as isNaN shouldn't constrain their parameter type as with global isNaN Number check functions such as isNaN shouldn't constrain their parameter type Jun 10, 2017
@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jun 10, 2017
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 10, 2017

Duplicate of #4002

Also see #15173 (comment)

@falsandtru
Copy link
Contributor Author

I searched it but probably I had some typo. Thanks.

@DanielRosenwasser
Copy link
Member

No worries! Sorry if that came off the wrong way, didn't mean to be abrasive.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants