What does the following type do? type NonNullable = T extends null | undefined ? never : T;

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following type do? type NonNullable = T extends null | undefined ? never : T;

Key points

  • Conditional type distributes over union types
  • NonNullable removes null and undefined values
  • Prevents T from being assigned null or undefined
  • Maintains type safety by restricting possible values

Ready to go further?

Related questions