Skip to content

Number.isFinite is missing type guard #43792

Closed
@Juraj-Masiar

Description

@Juraj-Masiar

Bug Report

The Number.isFinite accepts unknown parameter and returns true only if the parameter is Number.
So there should be a type guard saying it's a Number.
MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite

🔎 Search Terms

Number.isFinite

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Number.isFinite

⏯ Playground Link

Playground link with relevant code

💻 Code

function double(x: number | undefined): number {
  if (Number.isFinite(x)) {
    return x * 2;  // ERROR: Object is possibly 'undefined'.
  }
  return 0;
}

🙁 Actual behavior

ERROR: Object is possibly 'undefined'.

🙂 Expected behavior

No error :)

Activity

MartinJohns

MartinJohns commented on Apr 23, 2021

@MartinJohns
Contributor

Duplicate of #39090. Found using the search terms you provided in your issue. This has been rejected with a fairly good reason already.

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

        @MartinJohns@Juraj-Masiar@RyanCavanaugh

        Issue actions

          Number.isFinite is missing type guard · Issue #43792 · microsoft/TypeScript