prefer-type-fest-or
Require TypeFest Or<A, B> over two-element OrAll<[A, B]> boolean tuple checks.
Targeted pattern scopeโ
This rule targets direct and namespace-qualified references to OrAll<[A, B]> imported from type-fest.
What this rule reportsโ
OrAll<[A, B]>OrAll<readonly [A, B]>
Why this rule existsโ
Or is the dedicated TypeFest helper for checking whether either of two boolean types is true. It is shorter and more intention-revealing than spelling the same check as a two-element OrAll tuple.
โ Incorrectโ
import type { OrAll } from "type-fest";
type Either = OrAll<[false, boolean]>;
โ Correctโ
import type { Or } from "type-fest";
type Either = Or<false, boolean>;
Behavior and migration notesโ
- This rule only reports
OrAllimported fromtype-fest. - It only reports two-element tuple arguments.
- It skips named, optional, and rest tuple elements because those cannot be safely rewritten into ordinary generic arguments.
- Namespace-qualified
type-festreferences are reported too.
Additional examplesโ
โ Incorrect โ Namespace importโ
import type * as TypeFest from "type-fest";
type Either = TypeFest.OrAll<[true, boolean]>;
โ Correct โ Namespace importโ
import type { Or } from "type-fest";
type Either = Or<true, boolean>;
โ Correct โ More than two checksโ
import type { OrAll } from "type-fest";
type Any = OrAll<[false, boolean, true]>;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-or": "error",
},
},
];
When not to use itโ
Disable this rule if your codebase intentionally uses OrAll for all boolean disjunctions, including two-value checks.
Package documentationโ
TypeFest package documentation:
Source file: source/or.d.ts
/**
Returns a boolean for whether either of two given types is `true`.
*/
export type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
Rule catalog ID: R114