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
NonNullableDeepand inserting atype-festimport when absent. - โ Does not auto-fix where the
NonNullableDeepidentifier 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 removesnullandundefinedfrom all nested object properties.- Validate parity if your legacy
DeepNonNullablealias 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