We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Would it be useful to be able to convert a number in a string to a number literal type? '100' => 100.
'100'
100
I guess a more strictly typed Number.parseInt could take advantage of this.
Number.parseInt
type SomeNum = "100" extends `${infer U extends number}` ? U : never; // 100
We cannot do ParseNumber because if it doesn't match exactly, it just returns a number type instead of 100:
ParseNumber
number
type SomeNum = "100.0" extends `${infer U extends number}` ? U : never; // number
We could also maybe do ParseBoolean and maybe Is methods too (IsInteger)?
ParseBoolean
Is
IsInteger
Maybe it's not that useful. Feedback wanted.
The text was updated successfully, but these errors were encountered:
Hey landed here while I was exploring the 48094 PR. I think a type level string to number would be handy in some situations.
Yes, that's a bummer. But actually I found a workaround.
https://tsplay.dev/mbn8Pm
Here's the tweet where I was geeking about this today
Sorry, something went wrong.
No branches or pull requests
Would it be useful to be able to convert a number in a string to a number literal type?
'100'
=>100
.I guess a more strictly typed
Number.parseInt
could take advantage of this.We cannot do
ParseNumber
because if it doesn't match exactly, it just returns anumber
type instead of100
:We could also maybe do
ParseBoolean
and maybeIs
methods too (IsInteger
)?Maybe it's not that useful. Feedback wanted.
Upvote & Fund
The text was updated successfully, but these errors were encountered: