Skip to content
TypeScript

Type Guards API Reference

TypeScript type guards for narrowing types at runtime.

By EZ4Code Team

Type Guards

Runtime checks that narrow types in conditional branches.

typeof x === 'string'

Narrow primitive types using the typeof operator. Recognized: 'string', 'number', 'boolean', 'bigint', 'symbol', 'undefined', 'object', 'function'.

Returns: boolean

x instanceof Class

Narrow to an instance type by checking the prototype chain.

Returns: boolean

'key' in obj

Narrow a union type by checking for the presence of a property.

Returns: boolean

function isX(x: any): x is T

User-defined type guard. The 'x is T' return type predicate triggers narrowing when the function returns true.

Returns: x is T

More TypeScript API References