Skip to content

isNaN() should accept any value (in type definition) #13227

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
KostyaTretyak opened this issue Dec 30, 2016 · 2 comments
Closed

isNaN() should accept any value (in type definition) #13227

KostyaTretyak opened this issue Dec 30, 2016 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@KostyaTretyak
Copy link

TypeScript Version: 2.1.4

Code

isNaN('222');

Expected behavior:
Works without error

Actual behavior:
Throw error:

[ts] Argument of type '"222"' is not assignable to parameter of type 'number'.

@KostyaTretyak KostyaTretyak changed the title isNaN() should accept any value (in Type definition) isNaN() should accept any value (in type definition) Dec 30, 2016
@KostyaTretyak
Copy link
Author

This also applies to Number.isInteger(), Number.isNaN() methods.

For example, I have the following code:

function some(one: string | number)
{
  if( Number.isInteger(one) )
  {
    // Code...
  }
}

Why TypeScript throwing error?

Argument of type 'string | number' is not assignable to parameter of type 'number'.
Type 'string' is not assignable to type 'number'.

@DickvdBrink
Copy link
Contributor

@RyanCavanaugh explained it pretty clear in this issue why it is the way it is
#4002 (comment)

So it is by design

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 30, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants