prefer-type-fest-merge
Prefer Merge from type-fest over Omit<Destination, keyof Source> & Source and Except<Destination, keyof Source> & Source intersections.
This rule lives only in the experimental preset and reports without autofixing.
Targeted pattern scopeโ
This rule focuses on merge-style intersections that remove the overridden keys with builtin Omit or with Except from type-fest before intersecting with the overriding source type.
Omit<Destination, keyof Source> & SourceExcept<Destination, keyof Source> & Source- Either member order, including pairs inside larger intersections such as
Omit<Destination, keyof Source> & Source & Extra
What this rule reportsโ
This rule reports intersections when all of the following are true:
- one intersection member resolves to builtin
Omitor toExceptfromtype-fest - its second type argument is exactly
keyof Source - another member of the same intersection is exactly
Source
The rule is currently report-only. It does not autofix or suggest a replacement yet.
Why this rule existsโ
Merge<Destination, Source> states the override relationship directly.
- Readers do not need to unpack an
Omit- orExcept-plus-intersection recipe. - The canonical helper signals that the second type wins on overlapping keys.
- The upstream utility also simplifies the resulting object type for tooling display.
โ Incorrectโ
type Base = {
id: string;
name: string;
};
type Overrides = {
name: number;
readonly ok: true;
};
type Combined = Omit<Base, keyof Overrides> & Overrides;
โ Correctโ
import type { Merge } from "type-fest";
type Base = {
id: string;
name: string;
};
type Overrides = {
name: number;
readonly ok: true;
};
type Combined = Merge<Base, Overrides>;
Behavior and migration notesโ
prefer-type-fest-exceptdoes not report a builtinOmitthat matches this pattern, so the two rules do not double-report it.Except<Destination, keyof Source>only compiles when every key ofSourcealso exists onDestination.Merge<Destination, Source>has no such constraint, so it also covers sources that add new keys.- It ignores intersections whose sibling type does not match the
keyofoperand exactly. - Preserve any additional members. For example,
Omit<Base, keyof Overrides> & Extra & OverridesbecomesMerge<Base, Overrides> & Extra. - Check the operands before changing a named type. The rule reads syntax and cannot see through aliases.
Mergecan preserve union variants, drop call signatures, and handle index signatures differently from the handwritten intersection. Use this recommendation for plain object types.
Additional examplesโ
โ Incorrect โ Additional exampleโ
import type { Except as StrictExcept } from "type-fest";
type Base = {
id: string;
name: string;
};
type Overrides = {
name: number;
};
type Combined = Overrides & StrictExcept<Base, keyof Overrides>;
โ Correct โ Additional exampleโ
import type { Merge } from "type-fest";
type Base = {
id: string;
name: string;
};
type Overrides = {
name: number;
};
type Combined = Merge<Base, Overrides>;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [typefest.configs.experimental];
When not to use itโ
Disable this rule if your team prefers the explicit Omit<..., keyof ...> & ... or Except<..., keyof ...> & ... construction, or if you want to keep the override mechanism visible in source types.
Package documentationโ
TypeFest package documentation:
Source file: source/merge.d.ts
import type { Merge } from "type-fest";
type Foo = {
a: string;
b: number;
};
type Bar = {
a: number;
c: boolean;
};
type FooBar = Merge<Foo, Bar>;
//=> {a: number; b: number; c: boolean}
Rule catalog ID: R088