The do's and don'ts page warns that using any disables type checking for the parts of your program that use it, and recommends unknown when you do not know what type you want to accept or when you want to accept anything because you will be blindly passing it through without interacting with it. Catch clauses are the canonical case: because JavaScript can throw any type of value, TypeScript historically typed catch clause variables as any; TypeScript 4.0 added support for changing the type of the variable in a catch clause from any to unknown with an explicit catch (err: unknown) annotation, and TypeScript 4.4 introduced the useUnknownInCatchVariables flag, which changes the default type of catch clause variables from any to unknown and is enabled under the strict family of options. With the flag on, err.message errors with "'err' is of type 'unknown'" until you narrow, for example with if (err instanceof Error), and the reference notes this pattern makes error handling more comprehensive because you cannot guarantee that the object being thrown is an Error subclass ahead of time. Scope: TypeScript 4.4 and later with useUnknownInCatchVariables. Reviewed October 4, 2026.
Prefer unknown over any, including catch variables
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- www.typescriptlang.org
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.