Skip to content

TypeScript · maintainability

prefer-non-nullable-collection

eslint:prefer-non-nullable-collection

Suggest non-null arrays only when local control flow proves the nullish state is equivalent to an empty collection.

Default
error
Fix
none
Languages
typescript

Why

A redundant nullish collection state spreads defaults and guards through consumers without carrying information.

Fix

Use a non-null collection type and normalize omitted input to an empty collection at the boundary.

Before / after

Executed by this rule’s unit tests.

Before

Do not retain a redundant nullish state

src/search.ts · focus
interface Input { items: string[] | undefined } function search({ items = [] }: Input) { return items.length; }

After

Model an always-present collection

src/search.ts · focus
interface Input { items: string[] } function search({ items }: Input) { return items.length; }

Limits

  • The rule requires local evidence that nullish and empty values are treated identically and skips exported wire shapes.

Message IDs

preferNonNullableCollection