Skip to content

Any Type

In one line

The any type opts out of type checking entirely — a variable of type any can hold any value and perform any operation without compiler errors.

In simple words

The any type disables type checking for a value. A variable typed as any can hold any value, and you can call any method on it without TypeScript errors. It is the "escape hatch" from the type system.

While any is sometimes necessary (e.g., gradual migration, third-party libraries without types), it should be avoided in most code. It defeats the purpose of TypeScript — type errors slip through to runtime.

Prefer unknown over any for values of unknown type. Use any only when you truly need to opt out of checking, and narrow to a specific type as soon as possible.

Example

typescript
let x: any = 5;
x = "hello";    // OK: any accepts anything
x.foo();        // OK: any allows any method
x.bar.baz;     // OK: no type checking at all

// Prefer unknown instead
let y: unknown = 5;
// y.foo(); // Error: must narrow first

any disables all type checking. unknown is the safe alternative.

Common confusions

  • Confused with: unknown

    The difference: any allows all operations without checks; unknown requires narrowing. Always prefer unknown for untrusted data.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary