While solving a Advent of Typescript challenge, I stumbled upon a problem where I almost solved it but I had to convert a string constant to a number. Initially it seemed impossible to do it in TypeScript but eventually I found a way to do it using type template literals.

### Solution

```
type ToNumber<T> = T extends `${infer U extends number}` ? U : never;
const input = "123" as const;
type Input = typeof input;
// ^? type Input = "123"
type Output = ToNumber<typeof input>;
// ^? type Output = 123
```

To find and solve more TypeScript challenges like this, check out Advent of Typescript.