TypeScript Type Guards
10 functions
typeoftypeof value === 'string' | 'number' | ...Returns a string indicating the type of the operand.
instanceofvalue instanceof ClassNameTests whether the prototype property of a constructor appears anywhere in the prototype chain of an object.
in operator'key' in objectReturns true if the specified property is in the specified object.
Array.isArrayArray.isArray(value): booleanDetermines whether the passed value is an Array.
Number.isFiniteNumber.isFinite(value): booleanDetermines whether the passed value is a finite number.
Number.isIntegerNumber.isInteger(value): booleanDetermines whether the passed value is an integer.
Number.isNaNNumber.isNaN(value): booleanDetermines whether the passed value is NaN.
satisfiesvalue satisfies TypeValidates that an expression matches some type while keeping the inferred type. (TS 4.9+)
as constconst obj = { ... } as constAsserts that an object or array literal's values are treated as literal types.
type predicatefunction isT(v: unknown): v is T { ... }A user-defined type guard function that narrows the type of its argument.
