Skip to content
Justice Tech School

any, unknown and never

any switches off checking. unknown forces you to check before use. never is the type of values that cannot happen, such as a function that always throws.

Example
let a: any = 5;
let u: unknown = "text";
if (typeof u === "string") console.log(u.toUpperCase());
function fail(msg: string): never { throw new Error(msg); }
try { fail("boom"); } catch (e) { console.log((e as Error).message); }

Result

TEXT
boom

Exercise

Safe alternative to any.

let x:  = 1;

Quiz Test

Which type forces a check first?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.