Skip to content

prefer-non-nullable-collection

Suggest reviewing nullish arrays that use local empty-array defaults or a shared null-or-empty guard.

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.

Examples

Before — flagged Do not retain a redundant nullish state
src/search.ts
interface Input {
items: string[] | undefined;
}
function search({ items = [] }: Input) {
return items.length;
}
After — preferred Model an always-present collection
src/search.ts
interface Input {
items: string[];
}
function search({ items }: Input) {
return items.length;
}