Skip to content

isNaN parameter should be any (or unknown?) #37449

@victorz

Description

@victorz

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:

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

    Issue actions