'Convert number literal type to string literal type
I've seen questions about converting string literal types to number types (TypeScript: is there a way to convert a string literal type to a number type?), but not the other way around. Is there a way to define a type type NumberToString<N extends number> such that e.g. NumberToString<42> is 42?
The purpose of this is to provide a return type for Object.keys (in cases where I'm really, really sure that there are no extra properties).
Solution 1:[1]
Much much much simpler now with template literal types:
type NumberToString<N extends number> = `${N}`;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hittingonme |
