On this page
  1. any
  2. Syntax & Overview
  3. Notes & Pitfalls
  4. Example

any

Prev: `infer` | Up: builtins | Next: `enum`
Rel: unknown, builtins, Structural Typing & Narrowing
Ref: TypeScript Docs — any
Tags: #public #web #typescript #builtins #tier/legacy


Syntax & Overview

let x: any;

Disables type checking completely for x and silently propagates infectiously to expressions derived from it.

Legacy / Avoid: Prefer unknown in all new code.

Notes & Pitfalls

Example

// Prefer `unknown` over `any` at API boundaries:
function parseLength(raw: unknown): number {
  if (typeof raw === "string") return raw.length;
  throw new Error("Expected string");
}

Linked from

Related notes