Type Predicate

Noun · Development

Definitions

  1. A special return type annotation in TypeScript of the form `param is Type` that tells the compiler a boolean-returning function acts as a type guard — if the function returns true, the argument is narrowed to the specified type in subsequent code. This bridges runtime validation with compile-time type narrowing.

    In plain English: A function signature that tells TypeScript 'if this function returns true, you can safely treat the input as this specific type.'

    Example: "I wrote `function isUser(x: unknown): x is User` so that after the check, TypeScript knows the object has `.email` and `.name`."

Related Terms