Skip to content

String to Number

题目

Convert a string literal to a number, which behaves like Number.parseInt.

解答

ts
type ToNumber<S extends string> = S extends `${infer N extends number}`
  ? N
  : never;

Released under the MIT License.