prefer-type-fest-and
Require TypeFest And<A, B> over two-element AndAll<[A, B]> boolean tuple checks.
Targeted pattern scopeโ
This rule targets direct and namespace-qualified references to AndAll<[A, B]> imported from type-fest.
What this rule reportsโ
AndAll<[A, B]>AndAll<readonly [A, B]>
Why this rule existsโ
And is the dedicated TypeFest helper for checking whether two boolean types are both true. It is shorter and more intention-revealing than spelling the same check as a two-element AndAll tuple.
โ Incorrectโ
import type { AndAll } from "type-fest";
type Both = AndAll<[true, boolean]>;
โ Correctโ
import type { And } from "type-fest";
type Both = And<true, boolean>;
Behavior and migration notesโ
- This rule only reports
AndAllimported 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 Both = TypeFest.AndAll<[false, boolean]>;
โ Correct โ Namespace importโ
import type { And } from "type-fest";
type Both = And<false, boolean>;
โ Correct โ More than two checksโ
import type { AndAll } from "type-fest";
type All = AndAll<[true, boolean, false]>;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-and": "error",
},
},
];
When not to use itโ
Disable this rule if your codebase intentionally uses AndAll for all boolean conjunctions, including two-value checks.
Package documentationโ
TypeFest package documentation:
Source file: source/and.d.ts
/**
Returns a boolean for whether two given types are both `true`.
*/
export type And<A extends boolean, B extends boolean> = AndAll<[A, B]>;
Rule catalog ID: R113