A complete guide to TypeScript's never type

Click for: original source

TypeScript’s never type is very under-discussed, because it’s not nearly as ubiquitous or inescapable as other types. A TypeScript beginner can probably ignore never type as it only appears when dealing with advanced types, such as conditional types, or reading their cryptic type error messages. By Zhenghao.

The never type does have quite a few good use cases in TypeScript. However, it also has its own pitfalls you need to be careful of.

The article then describes:

  • What is never type
  • Why we need never type
  • How to use never type
  • How to read never type (from error messages)
  • How to check for never

In TypeScript, never is an empty set of values. In fact, in Flow, another popular JavaScript type system, the equivalent type is called exactly empty. Interesting read!

[Read More]

Tags programming javascript app-development frontend nodejs