type predicate

A return type written param is Type, which tells the compiler that when the function returns true, the argument has that type.

In more detail

A plain boolean function tells the caller nothing. function isNotNull<T>(val: T | null | undefined): val is T lets array.filter(isNotNull) produce a clean array of T. The compiler trusts the predicate, so its check must really be correct.

Example

function isObject(val: unknown): val is Record<string, unknown>

Related terms

Taught in

References