Skip to the solution
MediumFrontend10 min read

What is the never type?

114 views

The problem

Question presented to candidate: "What is the never type in TypeScript? Where does it show up on its own, and where would you write it deliberately?"

What a strong answer should cover:

  • never is the bottom type: the type with no values. It is assignable to every type, and nothing (not even any or unknown values) is assignable to it
  • Where it appears by itself: functions that cannot return normally, branches where narrowing has removed every member, impossible intersections like string & number, and [] inside an object literal (never[])
  • Algebra: T | never is T; a conditional type maps members to never to drop them (how Exclude works); key filtering with mapped types
  • Deliberate uses: exhaustiveness checks, forbidding a property with prop?: never
  • Traps: a distributive conditional over never gives never, so IsNever needs [T] extends [never]; never vs void vs unknown

Code / implementation expected: Optional β€” a few type-level checks, or an exhaustiveness helper.

  • never
  • void

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

10 min read Β· 10 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

TypeScriptThe rules of never and where it appears
TypeScriptnever in type-level code: filtering unions and IsNever

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 64 of 81 in TypeScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

What does as const do?

Continue