Skip to content

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

Closed
@falsandtru

Description

@falsandtru

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;

Activity

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`[/+] on Jun 9, 2017
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`[/+] on Jun 10, 2017
ghost

ghost commented on Jun 10, 2017

@ghost

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

falsandtru commented on Jun 10, 2017

@falsandtru
ContributorAuthor

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

falsandtru commented on Jun 10, 2017

@falsandtru
ContributorAuthor

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));
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[/+] on Jun 10, 2017
DanielRosenwasser

DanielRosenwasser commented on Jun 10, 2017

@DanielRosenwasser
Member

Duplicate of #4002

Also see #15173 (comment)

falsandtru

falsandtru commented on Jun 10, 2017

@falsandtru
ContributorAuthor

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

DanielRosenwasser

DanielRosenwasser commented on Jun 11, 2017

@DanielRosenwasser
Member

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

locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DanielRosenwasser@falsandtru

        Issue actions

          Number check functions such as `isNaN` shouldn't constrain their parameter type · Issue #16427 · microsoft/TypeScript