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 :
Much much much simpler now with template literal types:
type NumberToString<N extends number> = `${N}`;