Skip to main content

prefer-type-fest-is-null

Require TypeFest IsNull<T> over manual tuple-wrapped null conditional type guards.

Targeted pattern scopeโ€‹

This rule reports exact conditional type guards shaped like [T] extends [null] ? true : false.

It does not report distributive T extends null ? true : false checks.

What this rule reportsโ€‹

This rule reports manual non-distributive null checks that can be replaced by IsNull<T>.

  • [T] extends [null] ? true : false

Why this rule existsโ€‹

IsNull<T> makes null detection intent explicit and keeps type-guard helpers aligned with TypeFest.

โŒ Incorrectโ€‹

type Result<T> = [T] extends [null] ? true : false;

โœ… Correctโ€‹

type Result<T> = IsNull<T>;

Behavior and migration notesโ€‹

  • Only the canonical tuple-wrapped form is reported.
  • undefined and never guards are handled by their own rules.
  • Autofix is skipped when IsNull is shadowed in the local scope.

Additional examplesโ€‹

โŒ Incorrect โ€” Generic helperโ€‹

type Nullable<T> = [T] extends [null] ? true : false;

โœ… Correct โ€” Generic helperโ€‹

type Nullable<T> = IsNull<T>;

โœ… Correct โ€” Distributive conditionalโ€‹

type Nullable<T> = T extends null ? true : false;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-is-null": "error",
},
},
];

When not to use itโ€‹

Disable this rule if a public helper must keep a hand-written null conditional for teaching or compatibility reasons.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/is-null.d.ts

Rule catalog ID: R105

Further readingโ€‹

Adoption resourcesโ€‹