Skip to main content

prefer-type-fest-non-nullable-deep

Require TypeFest NonNullableDeep over DeepNonNullable aliases.

Targeted pattern scopeโ€‹

This rule reports DeepNonNullable<T> type references and prefers the canonical NonNullableDeep<T> from type-fest for recursive non-nullable transformations.

What this rule reportsโ€‹

  • Type references named DeepNonNullable.

Detection boundariesโ€‹

  • โœ… Reports direct DeepNonNullable<T> type references.
  • โœ… Autofixes by renaming the identifier to NonNullableDeep and inserting a type-fest import when absent.
  • โŒ Does not auto-fix where the NonNullableDeep identifier is shadowed by a type parameter in scope.

Why this rule existsโ€‹

NonNullableDeep<T> is the canonical TypeFest utility for recursively removing null and undefined from all nested properties.

Using a consistent name avoids confusion between locally-defined deep-non-nullable helpers and the official TypeFest utility. The canonical name also communicates intent to contributors familiar with type-fest.

โŒ Incorrectโ€‹

type StrictConfig = DeepNonNullable<Config>;

โœ… Correctโ€‹

import type { NonNullableDeep } from "type-fest";

type StrictConfig = NonNullableDeep<Config>;

Behavior and migration notesโ€‹

  • NonNullableDeep<T> recursively removes null and undefined from all nested object properties.
  • Validate parity if your legacy DeepNonNullable alias had different behavior for arrays, maps, or sets.
  • Prefer explicit narrowing over deep non-nullable transformation where the required shape is known at the call site.

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-non-nullable-deep": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your codebase intentionally standardizes DeepNonNullable naming or if your local alias provides additional constraints not present in the TypeFest utility.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/non-nullable-deep.d.ts

/**
Deeply remove `null` and `undefined` from all properties of `T`.

Use-cases:
- Removing optional and nullable markers after a data-hydration step.
- Ensuring a configuration object has all required values present.

@example
```
import type {NonNullableDeep} from 'type-fest';

interface Config {
host: string | null;
port: number | undefined;
}

type StrictConfig = NonNullableDeep<Config>;
// => { host: string; port: number }
```

@category Object
*/

Rule catalog ID: R098

Further readingโ€‹

Adoption resourcesโ€‹