Is it possible to convert string union type to number union type in TypeScript?
e.g. Given a union type A:
type A = '7' | '8' | '9'
Convert to:
type B = 7 | 8 | 9
The numbers in A can be any number, not just digits or integers.
Going from string to number is not possible, as far as I know. However, how about the other way around, would that work for you? You can do this by using template literals:
type B = 7 | 8 | 9;
type A = `${B}`;