Prototype: Numeric Literal Types by weswigham · Pull Request #7480 · microsoft/TypeScript (original) (raw)

This is a prototype for numeric literal types, in the same vein as string literal types.

All numeric syntaxes supported by JS should be supported (as far as I know) in type positions. Additionally, NaN and Infinity are builtin to the typespace as literal subclasses of number.

Also with this change:

There are tests testing guards against numeric literal types which I'll uncomment/add after #7235 is merged.

My open questions/thoughts:

I probably had more questions, but I want to put this out for people to see for now. This isn't something that should be considered ready to use, but it should be a great place to start looking at what's feasible.