Type guard that checks if a value is a boolean.
Type Narrowing Behavior:
unknown
boolean
true
true | false
The value to check
true if u is a boolean, false otherwise. When true, TypeScript narrows the type to boolean.
u
false
const flags: unknown[] = [true, 'no', false];const booleans = flags.filter(isBoolean);assert.deepStrictEqual(booleans, [true, false]); Copy
const flags: unknown[] = [true, 'no', false];const booleans = flags.filter(isBoolean);assert.deepStrictEqual(booleans, [true, false]);
Type guard that checks if a value is a boolean.
Type Narrowing Behavior:
unknown
toboolean
whentrue
true | false
)