Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 728 Bytes

File metadata and controls

45 lines (33 loc) · 728 Bytes

typelab / utils / ParseBoolean

type ParseBoolean<T> = T extends boolean ? T : T extends 0 | 0 | 0n | 0n | "" | null | undefined | Void ? false : T extends 1 ? true : T extends `${infer U extends boolean}` ? U : never;

Converts a type to a boolean.

Type Parameters

Type Parameter Description

T

The type to convert.

Returns

The boolean representation of the type.

Example

type True1 = ParseBoolean<'true'>; // true
type True2 = ParseBoolean<1>; // true
type False1 = ParseBoolean<'false'>; // false
type False2 = ParseBoolean<0>; // false