Is there a method to alter literal types in TypeScript, for instance.
type T1 = "";
type T2 = 1
I am interested in obtaining string
for T1
and number
for T2
.
Regarding collections, I am unsure, but I assume it would involve applying it to the generic type, though that is not my main concern at the moment.
In my current scenario, I am extracting the type from a generic function with a const annotation.
const f = <const T>(x:T)=> ...
since I require the precise literal type but also a more general type (its supertype?)
At this point, the only solution I can think of involves creating a type that manually checks if the type extends it and then returns that corresponding type.
type Z<T>=T extends string ? string : T extends number ? number ...
This approach should suffice if no other alternatives are available.
Thank you for any assistance.