Typescript - never

never is used when you are sure that something is never going to occur. Like a function always throw an error.

function throwError(errorMsg: string): never {
throw new Error(errorMsg);
}

Effectively throws an error whenever it is defined

let x: never = true;
// Error: Type 'boolean' is not assignable to type 'never'.

It can also be used for Exhaustive Checks

interface Square { kind: "square"; size: number; }
// Someone just added this new `Circle` Type
// We would like to let TypeScript give an error at any place that *needs* to cater for this.
// Like this area function below
interface Circle { kind: "circle"; radius: number; }

type Shape = Square | Circle;
function area(s: Shape) {
switch (s.kind) {
case "square": return s.size * s.size;
default: const _exhaustiveCheck: never = s;
// Got error TS2322: Type 'Circle' is not assignable to type 'never'.
}
}
// Need to add logic for Circle
function area(s: Shape) {
switch (s.kind) {
case "square": return s.size * s.size;
case "circle": return Math.PI * s.radius * s.radius;
default: const _exhaustiveCheck: never = s;
}
}