TypeScript 7 · Utility types and narrowing

Write a type guard

Tell the compiler how a check narrows a value.

function isString(value: unknown): value is string {
  return typeof value === "string";
}

Official TypeScript 7 documentation

More utility types and narrowing commands

All utility types and narrowing commands · TypeScript 7 cheatsheet

Was this page helpful?