prefer-type-fest-is-nullable
Require TypeFest IsNullable<T> over equivalent any-safe nullable conditional type guards.
Targeted pattern scopeโ
This rule reports exact nullable guards that preserve TypeFest's any behavior:
IsAny<T> extends true ? true : Extract<T, null> extends never ? false : true0 extends 1 & T ? true : Extract<T, null> extends never ? false : true
It does not report the shorter Extract<T, null> extends never ? false : true form because that returns a different result for any.
What this rule reportsโ
This rule reports manual null-membership checks that can be replaced by IsNullable<T> without losing TypeFest's any handling.
Why this rule existsโ
IsNullable<T> makes nullable intent explicit and avoids repeating a nested conditional helper every time a type needs to detect null.
โ Incorrectโ
import type { IsAny } from "type-fest";
type Result<T> = IsAny<T> extends true ? true : Extract<T, null> extends never ? false : true;
โ Correctโ
import type { IsNullable } from "type-fest";
type Result<T> = IsNullable<T>;
Behavior and migration notesโ
IsAny<T>must be imported fromtype-festfor the imported-helper pattern to report.- The manual
0 extends 1 & Tany guard is also supported. - The inner check must be exactly
Extract<T, null> extends never ? false : true. - Autofix is skipped when
IsNullableis shadowed in the local scope.
Additional examplesโ
โ Incorrect โ Manual any guardโ
type Result<T> = 0 extends 1 & T ? true : Extract<T, null> extends never ? false : true;
โ Correct โ Manual any guardโ
type Result<T> = IsNullable<T>;
โ Correct โ Not any-safeโ
type Result<T> = Extract<T, null> extends never ? false : true;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-is-nullable": "error",
},
},
];
When not to use itโ
Disable this rule if a public helper must keep a hand-written nullable conditional for compatibility or teaching reasons.
Package documentationโ
TypeFest package documentation:
Source file: source/is-nullable.d.ts
Rule catalog ID: R116