Skip to content

Infinities as number literal typesΒ #56272

@Andarist

Description

@Andarist

πŸ”Ž Search Terms

infinity number literal

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20231031#code/C4TwDgpgBACg9gZwJbCQNwgSQHYDMnYohQC8UAjBAJw0DcAUAPSNSsB6A-PaJFAHIQA5gENUGHPkKhSUALSUaVBs1ZRO9IA

πŸ’» Code

type PositiveInfinity = 1e999;
//   ^?
type NegativeInfinity = -1e999;
//   ^?

πŸ™ Actual behavior

In TS 5.2 we get NumberLiteralTypes with Infinity and -Infinity values.

In the upcoming TS 5.3 we get a number type in the of the PositiveInfinity

πŸ™‚ Expected behavior

I don't know. I created this issue to discuss exactly that.

Should this part of the change be reverted and should Infinity be allowed as a literal number value? Or should -Infinity be aligned with Infinity and should it be converted~ to a number type as well?

Additional information about the issue

I didn't see an Infinity as a literal type so I made this change while working in this area. @rbuckton commented here:

I really hope no one is relying on this.

but it turns out that some try to rely on this. We can see it in this issue, cc @Max10240

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions