According to the spec (see references below), isNaN() should be able to take any kind of value, which would be coerced into a number (using something like Number(value), which seems to make sense from my tests).
Forcing the parameter to be number breaks legacy code which relies on being able to pass string arguments to isNaN().
function f(value: string) {
if (isNaN(value)) { // compilation error, but should be OK
...
}
}
Removing the string type from the value parameter admittedly fixes the compilation error, but breaks the "no implicity any" rule.
References:
Please respect the issue templates for bug reports and feature requests.
Both issue templates urge you to first search for existing issues and asks for information (including the search terms you have used to search for existing issues).
This is a duplicate of:
Search terms used: isNaN
Forcing the parameter to be
numberbreaks legacy code which relies on being able to pass string arguments toisNaN().
For this case you have several options:
isNaN yourself using declaration merging.isNaN.isNaN function that accepts any argument, then within your custom function call the existing isNaN function (I'd opt for this approach).Huh. Fair enough. I see your point in alternate solutions.
However, the original reason for closing the first report of this issue is incorrect. https://github.com/microsoft/TypeScript/pull/3947#issuecomment-123558773
Reading more the ecmascript doc the argument is specified as Number.
"Number" in the spec is not the type, confusingly enough. It's the parameter name. That becomes evident when you read the algorithm for isNaN().
Regarding searching for issues and issue templates: I simply found the line of code I was looking for in the GitHub project file browser, clicked the little ellipsis next to the line number, and selected "Reference this in a new issue." There was no issue template. Sorry for that, I suppose. I typed "isNaN" in the title but none of the "similar issues" were the same as this one in my opinion. I don't mean to get defensive but I tried and sometimes mistakes happen.
Either way, I still feel like this is in violation of the spec, and that Number.isNaN() should be the one whose parameter should have type number.
Thank you for your consideration.
Most helpful comment
Please respect the issue templates for bug reports and feature requests.
Both issue templates urge you to first search for existing issues and asks for information (including the search terms you have used to search for existing issues).
This is a duplicate of:
Search terms used:
isNaNFor this case you have several options:
isNaNyourself using declaration merging.isNaN.isNaNfunction that acceptsanyargument, then within your custom function call the existingisNaNfunction (I'd opt for this approach).