Course contentsShow
← TypeScript
Lesson 950 of 1,79622. The never TypeFree lesson

Array and Object with never

What never[] means versus Array<never>, and how never properties affect object types.

Array and Object with never

You'll learn what happens when never shows up as an element type in arrays or as a property type in objects, and why these combinations have unexpected (but logical) behavior.


What never[] Actually Means

When you write never[] or Array<never>, you're describing an array whose elements are of type never. Since nothing can actually be assigned to never, this means the array can only be empty.

const arr1: never[] = []; // ✓ Valid
const arr2: Array<never> = []; // ✓ Same thing, valid

// const arr3: never[] = [1]; // ✗ Error: number not assignable to never
// const arr4: never[] = ["hi"]; // ✗ Error: string not assignable to never

Both syntaxes (never[] and Array<never>) mean the same thing: an array that can never contain any elements.


never[] as an Impossible Constraint

You might encounter never[] when union types collapse or when generic constraints eliminate all possibilities:

type OnlyNumbers<T> = T extends number ? T : never;

type Result = OnlyNumbers<string | boolean>; // never
type ArrayOfResult = Result[]; // never[] — can only be []

This acts as a compile-time signal: "No valid values exist for this array."


Objects with never Properties

When an object type has a property typed as never, that property cannot be assigned any value:

type Impossible = {
  name: string;
  value: never;
};

// const obj: Impossible = {
//   name: "test",
//   value: 42 // ✗ Error: number not assignable to never
// };

You cannot construct a valid instance of Impossible because there's no value that satisfies value: never.


Why This Matters: Filtering Properties

Objects with never properties appear most often in mapped type filtering, where you intentionally use never to remove unwanted properties:

type FilterStrings<T> = {
  [K in keyof T]: T[K] extends string ? never : T[K];
};

type Original = { name: string; age: number };
type Filtered = FilterStrings<Original>;
// Evaluates to: { name: never; age: number }

While name: never looks odd, it signals that name should be excluded in more advanced patterns.


Practical Takeaway

In real-world code, never[] usually means "this branch cannot produce any values," and never properties signal "this field should not exist." These aren't bugs—they're compile-time evidence that certain code paths or property combinations are impossible.

Key Takeaway: never[] describes an array that can only be empty, and object properties typed as never cannot be assigned any value—both serve as type-level "impossibility markers" that help TypeScript eliminate invalid states.