@cuppachino/type-space
Version:
A collection of type utilities for TypeScript.
13 lines (12 loc) • 423 B
TypeScript
import type { NumberLiteral, ParseNumberLiteral } from '../index.js';
/**
* Coerce either a `number` or a `NumberLiteral` into a `number`.
*
* @remarks This is useful for finalizing a `NumberLike` into a `number`.
* @example
* ```
* type A = IntoNumber<1> // 1
* type B = IntoNumber<"1"> // 1
* ```
*/
export type IntoNumber<T extends number | NumberLiteral> = T extends NumberLiteral ? ParseNumberLiteral<T> : T;