What is the never type in TypeScript?

Answer

The never type represents values that never occur — it is the type of expressions that never complete normally. Two primary use cases: (1) Functions that never return — either because they always throw an error or run in an infinite loop: function fail(msg: string): never { throw new Error(msg); }. (2) Exhaustiveness checking — in a switch statement over a discriminated union, after handling all cases, the variable in the default case has type never. If a new union member is added without a corresponding case, the type will not be never and TypeScript will report an error — great for enforcing completeness. never is also the result of intersecting incompatible types: string & number is never. Every type is a supertype of never, meaning never can be assigned to any type. never is assignable to all types but nothing is assignable to never (except itself).