Skip to main content

prefer-type-fest-not

Use Not<Flag> to negate a boolean type expressed as If<Flag, false, true>. This experimental rule requires type-fest 6.x.

Targeted pattern scopeโ€‹

The rule checks that If resolves to a named, aliased, or namespace import from type-fest and that its second and third arguments are the literal types false and true, in that order.

What this rule reportsโ€‹

The diagnostic highlights the complete If reference. Local types with the same name and ordinary TypeScript conditional types are outside its scope.

Why this rule existsโ€‹

TypeFest defines Not<A> as If<A, false, true>. Both accept boolean type parameters and produce the same results for boolean, any, and never.

โŒ Incorrectโ€‹

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

export type IsDisabled<Enabled extends boolean> = If<Enabled, false, true>;

โœ… Correctโ€‹

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

export type IsDisabled<Enabled extends boolean> = Not<Enabled>;

Behavior and migration notesโ€‹

The replacement keeps the condition as written. A comment inside the expression or a conflicting local binding can make the diagnostic report-only.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/not.d.ts

Rule catalog ID: R146

Further readingโ€‹