prefer-type-fest-less-than
Require TypeFest LessThan<A, B> over boolean wrappers built from GreaterThanOrEqual<A, B>.
Targeted pattern scopeโ
This rule targets equivalent conditional wrappers such as GreaterThanOrEqual<A, B> extends true ? false : true and infer-wrapped variants.
What this rule reportsโ
- Conditional types equivalent to
LessThan<A, B>that are composed fromGreaterThanOrEqual<A, B>.
Why this rule existsโ
LessThan is the canonical TypeFest numeric comparison helper for strict < checks. Using it directly is shorter, clearer, and avoids repetitive wrapper patterns.
โ Incorrectโ
import type { GreaterThanOrEqual } from "type-fest";
type IsLess = GreaterThanOrEqual<1, 2> extends true ? false : true;
โ Correctโ
import type { LessThan } from "type-fest";
type IsLess = LessThan<1, 2>;
Behavior and migration notesโ
- This rule targets wrappers equivalent to
LessThan<A, B>. - It handles direct and infer-wrapped conditional forms.
- It does not report wrappers whose boolean branches do not match strict
<semantics.
Additional examplesโ
โ Incorrect โ Additional exampleโ
import type { GreaterThanOrEqual } from "type-fest";
type IsLess =
GreaterThanOrEqual<4, 9> extends infer Result
? Result extends true
? false
: true
: never;
โ Correct โ Additional exampleโ
import type { LessThan } from "type-fest";
type IsLess = LessThan<4, 9>;
โ Correct โ Repository-wide usageโ
type IsNegative<N extends number> = LessThan<N, 0>;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-less-than": "error",
},
},
];
When not to use itโ
Disable this rule if your codebase intentionally standardizes on custom numeric wrapper types.
Package documentationโ
TypeFest package documentation:
Source file: source/less-than.d.ts
/**
Returns a boolean for whether a given number is less than another number.
*/
export type LessThan<A extends number, B extends number> = ...
Rule catalog ID: R084