Never in conditional types
Concept and syntax
In a distributive conditional, never behaves as an empty union, so there are no branches to evaluate. To detect never itself, compare wrapped types instead. Testing T extends never with a naked T does not produce true for T = never.
Working example
Save each snippet separately as main.ts in a fresh directory with TypeScript 5.8.3. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError main.ts and run accepted snippets with node main.js. Type aliases are erased; assignments and diagnostic checks demonstrate the type relations, not the printed output alone.
type IsNever<T>=[T] extends [never] ? true:false; type Naked<T>=T extends never?true:false;const x:IsNever<never>=true; function impossible(v:Naked<never>):never{return v;} console.log(x);Expected output:
trueCommon mistake
Intentionally invalid; compile separately and do not execute.
type IsNever<T>=[T] extends [never] ? true:false; type Naked<T>=T extends never?true:false;const x:Naked<never>=true;Expected diagnostic: TS2322. Naked<never> evaluates to never; use the wrapped check.
Practice and recap
Test IsNever<string> and IsNever<never | string>.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Never in conditional types — knowledge check
Check the type transformation, trace output, diagnose a rejected example, and apply the concept to a new case.
Which statement about Never in conditional types is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
type IsNever<T>=[T] extends [never] ? true:false; type Naked<T>=T extends never?true:false;const x:IsNever<never>=true; function impossible(v:Naked<never>):never{return v;} console.log(x);Which diagnostic and explanation match the rejected example under the lesson settings?
type IsNever<T>=[T] extends [never] ? true:false; type Naked<T>=T extends never?true:false;const x:Naked<never>=true;What is IsNever<never | string>?