Skip to content

Missing error for enum using non-number variables named Infinity/NaNΒ #54981

Closed
@nicolo-ribaudo

Description

@nicolo-ribaudo

Bug Report

πŸ”Ž Search Terms

enum number infinity nan

πŸ•— Version & Regression Information

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

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

{
  let Infinity = {};
  enum En {
    X = Infinity
  }
}

{
  let NaN = {};
  enum En {
    X = NaN
  }
}

{
  let SomethingElse = {};
  enum En {
    X = SomethingElse
  }
}

πŸ™ Actual behavior

TS reports "Type '{}' is not assignable to type 'number' as required for computed enum member values" only for X = SomethingElse

πŸ™‚ Expected behavior

TS should also report an error for X = Infinity and X = NaN.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions