TypeScript error: Property does not exist on type 'never'
Quick answer
TypeScript narrowed a union type down to `never` — usually because a type guard eliminated every possible case, or two incompatible branches were merged. Check the type guard's conditions; there's almost always a logic mistake making the narrowing too aggressive.
What causes this error
never represents a type that TypeScript believes is impossible to reach. It shows up most often when a series of if/else or switch branches, combined with type guards, has (in TypeScript's view) eliminated every member of a union type — leaving nothing left, so any property access is flagged.
The Fix
type Shape = { kind: 'circle'; radius: number } | { kind: 'square'; side: number };
function area(shape: Shape) {
if (shape.kind === 'circle') {
return Math.PI * shape.radius ** 2;
}
if (shape.kind === 'square') {
return shape.side ** 2;
}
// shape is narrowed to `never` here — correct, since both cases are handled
}
// If you see this error unexpectedly, check for a typo in a discriminant
// check (e.g. comparing shape.kind === 'circl' by mistake), which makes
// TypeScript think that branch is unreachable.Common causes / variations
- A typo in a string literal comparison used as a type guard
- An exhaustive
switchwhere a new union member was added to the type but not handled in the switch - Merging two functions with incompatible parameter types, collapsing the parameter type to
never
Related errors
See also: Object is possibly 'null'.
Was this fix helpful?
Comments
Loading comments...