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.
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
:
type SomeNum = "100.0" extends `${infer U extends number}` ? U : never;
// number
We could also maybe do ParseBoolean
and maybe Is
methods too (IsInteger
)?
Maybe it's not that useful. Feedback wanted.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too