-
-
Notifications
You must be signed in to change notification settings - Fork 0
type boolean
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
export type IsBoolean<T, True = true, False = false> = [T] extends [boolean]
? [boolean] extends [T] ? True : False
: False;Checks if the type T is the generic type
boolean, returning True if it is, and
False if not.
This predicate is not satisfied by just true or false; the type must be a
union of both (true | false, which is what the boolean type actually
represents) to result in a positive match.
T-
True(default:true) -
False(default:false)
Types Boolean
import type { IsBoolean } from "@nick/is/type/boolean";
type A = IsBoolean<true>; // false
type B = IsBoolean<false>; // false
type C = IsBoolean<boolean | 0>; // false
type Y = IsBoolean<true | false>; // true
type Z = IsBoolean<boolean>; // trueexport type IsFalse<T, True = true, False = false> = [T, false] extends
[false, T] ? True : False;Checks if the type T is specifically false,
returning True if it is, and
False if not.
T-
True(default:true) -
False(default:false)
Types Boolean
import type { IsFalse } from "@nick/is/type/boolean";
type A = IsFalse<true>; // false
type B = IsFalse<false>; // true
type C = IsFalse<boolean>; // falseexport type IsTrue<T, True = true, False = false> = [T, true] extends [true, T]
? True
: False;Checks if the type T is specifically true,
returning True if it is, and
False if not.
T-
True(default:true) -
False(default:false)
Types Boolean
import type { IsTrue } from "@nick/is/type/boolean";
type A = IsTrue<true>; // true
type B = IsTrue<false>; // false
type C = IsTrue<boolean>; // false