CodeZettaInterview Hub

TypeScript · Type Guards · Fresh / Intern · Concept

What is a user-defined type guard?

Short Interview Answer

Function returning `arg is Type` that narrows when true.

Detailed Explanation

Implement runtime check correctly — TS trusts the predicate.

Example

function isString(x: unknown): x is string {
  return typeof x === 'string';
}

Did you know this answer?