@cuppachino/type-space
Version:
A collection of type utilities for TypeScript.
14 lines (13 loc) • 442 B
TypeScript
import type { NumberLiteral } from './number-literal';
import type { Stringify } from './stringify';
/**
* Coerces a `NumberLiteral` type to a `number`
*
* @see {@link NumberLiteral}
* @example
* ```
* type Positive42 = ParseNumberLiteral<'42'> // 42
* type Negative42 = ParseNumberLiteral<'-42'> // -42
* ```
*/
export type ParseNumberLiteral<N extends NumberLiteral> = Stringify<N> extends `${infer I extends number}` ? I : never;