any says "trust me". unknown says "prove it".
Direct answer
Use unknown instead of any when you do not know a value's type. any allows anything and turns off checking. unknown accepts any value but you must narrow it with checks before using it.
Example
let a: any = "hello";
a.toFixed(); // no error, crashes at runtime
let u: unknown = "hello";
// u.toUpperCase(); // error
if (typeof u === "string") {
u.toUpperCase(); // fine
}
Good use for unknown
function parse(text: string): unknown {
return JSON.parse(text);
}
try {
// ...
} catch (error: unknown) {
if (error instanceof Error) console.log(error.message);
}
Where Teyro fits
Teyro's TypeScript for Beginners course turns this into short lessons you can play in a few minutes a day. It has 20 lessons, and you can start free.
The bottom line
Prefer unknown. Treat any as a last resort.



