My type declaration looks like this:
type To_String<N extends number> = `${N}`
I have created a Type that maps the resulting string number as follows:
type Remap<Number>
= Number extends '0'
? 'is zero'
: Number extends '1'
? 'is one'
: Number extends '2'
? 'is two'
: 'other number'
type One = Remap<To_String<1>> // 'is one'
type Other = Remap<To_String<5>> // 'other number'
Everything seems to be working fine so far, but then I encounter an issue when trying to pass just 'number', such as when attempting to call a function that returns a 'number'. I'm struggling to figure out how to match against the resulting type that is represented in backticks and matches against a string:
type Remap<Number>
// = Number extends `${number}` - attempt that catches all values
= Number extends '${number}' // not matched against string version
? 'is Template literal result'
: Number extends '1'
? 'is one'
: Number extends '2'
? 'is two'
: 'other number'
// this gives a result type enclosed in backticks that still passes as a string
type Template_String_Result = To_String<number> // `${number}`
// an attempt that fails to catch the top match clause
type Non_Literal_Number = Remap<To_String<number>>
Is there a way to match against this Template literal string?