Skip to main content

prefer-type-fest-distributed-pick

Prefer DistributedPick from type-fest over distributive conditional helpers built from Pick.

This rule lives only in the experimental preset and reports without autofixing.

Targeted pattern scopeโ€‹

This rule focuses on the common helper shape that distributes Pick over a union manually:

  • Union extends unknown ? Pick<Union, Key> : never
  • Union extends any ? Pick<Union, Extract<Key, keyof Union>> : never

It intentionally ignores ordinary non-distributive Pick usage and unrelated conditional helpers.

What this rule reportsโ€‹

This rule reports conditional helpers when all of the following are true:

  • the false branch is never
  • the conditional distributes over the checked type with extends unknown or extends any
  • the true branch is exactly Pick<CheckedType, KeyType> or Pick<CheckedType, Extract<KeyType, keyof CheckedType>>

The rule is currently report-only. It does not autofix or suggest a replacement yet.

Why this rule existsโ€‹

DistributedPick<ObjectType, KeyType> makes the union-preserving behavior explicit.

  • The helper reads as a named concept instead of a conditional-type trick.
  • It communicates why plain Pick is not enough for union-heavy object types.
  • Standardizing on the upstream utility reduces local helper drift.

โŒ Incorrectโ€‹

type OnlyKeys<Union, Key extends PropertyKey> =
Union extends unknown ? Pick<Union, Key> : never;

โœ… Correctโ€‹

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

type OnlyKeys<Union, Key extends PropertyKey> =
DistributedPick<Union, Key>;

Behavior and migration notesโ€‹

  • This rule only reports the narrow distributive-Pick helper pattern.
  • It accepts the Extract<Key, keyof Union> variant because that is a common way to keep the built-in Pick constraint satisfied.
  • It does not report plain Pick<T, K> usage.

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 project prefers a local helper name for distributive picking or if you intentionally avoid Type-Fest for object-union utilities.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/distributed-pick.d.ts

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

type Result<Union, Key extends PropertyKey> = DistributedPick<Union, Key>;

Rule catalog ID: R091

Further readingโ€‹

Adoption resourcesโ€‹