Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinities as number literal types #56272

Open
Andarist opened this issue Oct 31, 2023 · 4 comments
Open

Infinities as number literal types #56272

Andarist opened this issue Oct 31, 2023 · 4 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@Andarist
Copy link
Contributor

🔎 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

@jcalz
Copy link
Contributor

jcalz commented Oct 31, 2023

Cross-linking #32277 and #31752

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Oct 31, 2023
@weswigham
Copy link
Member

weswigham commented Nov 2, 2023

Also see the original PR and my original PR. My first version had NaN and Infinity types - they're not hard to add if you implement them as compiler internal symbols - @ahejlsberg wanted the compelling usecases for them enumerated before we'd add them, though. Not sure anyone's going to be happy if the only usecase is arithmetic in the typesystem...

@fatcerberus
Copy link

Not sure anyone's going to be happy if the only usecase is arithmetic in the typesystem...

Or negated types. number & !NaN, etc.

@ExE-Boss
Copy link
Contributor

ExE-Boss commented Dec 3, 2023

Also cross‑linking: #28682, #42905, and #51741

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants