any turns off meaningful type checking for a value, unknown accepts a value but requires you to establish its type before using it, and never represents a value that cannot occur. Use unknown for data you have not validated, reserve any for deliberate opt-outs, and use never for impossible cases and exhaustive control flow.
How the three types differ
| Type | Meaning | What TypeScript permits | Typical use |
|---|---|---|---|
any |
Treat this value as unchecked. | Allows arbitrary property access and calls, and lets the value flow into more specific types without verification. | A deliberate escape hatch at an untyped boundary or during gradual migration. |
unknown |
This value could be anything; establish what it is before using it. | Accepts values of any type, but blocks most operations and assignments to specific types until the value is narrowed or asserted. | External or dynamic input whose structure has not yet been validated. |
never |
No value can exist here. | Can be assigned to every type; no type other than never is assignable to it. |
Functions that do not complete and exhaustive handling of union types. |
These are not simply three points on a strictness scale. any weakens checking; unknown preserves uncertainty and requires proof before use; never represents the absence of possible values. In assignment compatibility, unknown acts as a top type and never as a bottom type. any has special escape-hatch behavior; it is not assignable to never. See the TypeScript Handbook’s type compatibility rules.
As an Amazon Associate I earn from qualifying purchases.
When to use unknown
Choose unknown when a value enters your program without a type you can trust—for example, data from a dynamic source. You can receive any value as unknown, but TypeScript will not let you treat it as a string, object, or other specific type until you narrow it or assert a type. Narrowing with a runtime check is generally useful because it verifies the value before code relies on it.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallfunction describe(value: unknown): string {
if (typeof value === "string") {
return value.toUpperCase();
}
return "not a string";
}
Here, the typeof check narrows value to string inside the branch, so calling toUpperCase() is permitted. Depending on the value, narrowing can use checks such as typeof, comparisons, instanceof, or a user-defined type predicate. The Handbook’s basic types guide describes unknown as requiring this kind of checking or an assertion before use as a more specific type.
#1 Best Overall
When any is appropriate—and what it costs
any is useful only when you intentionally want to opt out of checking, such as temporarily accommodating an untyped boundary during a migration. It does not mean “not yet known, but safe.” Once a value is typed any, arbitrary property access and calls can compile, and the value can be assigned to a specific type without proving that it matches. A nonexistent property can therefore pass the compiler and fail at runtime.
The Handbook describes that convenience as coming at the cost of type safety and recommends avoiding any when it is not necessary. If the value is merely unvalidated, use unknown and narrow it instead.
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
When never appears
never represents a value that cannot occur. A function whose execution never completes can declare never as its return type. For example, a function that always throws does not return a value:
Free tools Windows power users keep installed
One-click scans. No signup required.
function fail(message: string): never {
throw new Error(message);
}
never can also result from control-flow narrowing. If checks have ruled out every possible member of a union, no value remains in that branch. The Handbook’s explanation of never covers both non-returning functions and impossible narrowed cases.
Use never to check exhaustive unions
Assigning the remaining value to never in a final branch makes the compiler flag a newly added union variant that earlier branches do not handle. This is useful when a union is intended to be handled completely.
type Shape =
| { kind: "circle"; radius: number }
| { kind: "square"; side: number };
function area(shape: Shape): number {
switch (shape.kind) {
case "circle":
return Math.PI * shape.radius ** 2;
case "square":
return shape.side ** 2;
default: {
const impossible: never = shape;
return impossible;
}
}
}
If a new shape is added to Shape without adding a matching case, shape in the default branch will no longer be assignable to never, exposing the missing handling at compile time. The assignment behavior is documented in the type compatibility reference.
Quick decision guide
- Use
unknownwhen a value might be anything and must be checked before use. - Use
anyonly when bypassing type checking is an intentional trade-off. - Use
neverwhen a value or control-flow branch is impossible, or to make union handling exhaustive.
The TypeScript 3.0 release notes introduced unknown as “the type-safe counterpart of any.” That is the practical distinction: uncertainty can remain safely represented by unknown, while any discards the compiler’s protection.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




