prefer-type-fest-conditional-pick
Require TypeFest ConditionalPick<T, Condition> over imported aliases like PickByTypes.
Targeted pattern scopeโ
This rule targets imported alias names that mirror TypeFest conditional property selection semantics.
What this rule reportsโ
- Type references that resolve to imported
PickByTypesaliases.
Why this rule existsโ
ConditionalPick is the canonical TypeFest utility for selecting fields by value type. Standardizing on TypeFest naming improves discoverability and improves consistency.
โ Incorrectโ
import type { PickByTypes } from "type-aliases";
type StringProps = PickByTypes<User, string>;
โ Correctโ
import type { ConditionalPick } from "type-fest";
type StringProps = ConditionalPick<User, string>;
Behavior and migration notesโ
ConditionalPick<T, Condition>selects keys whose value types extendCondition.- This rule targets alias names with equivalent semantics (
PickByTypes). - Keep aliases only when they intentionally add behavior beyond simple conditional key filtering.
Additional examplesโ
โ Incorrect โ Additional exampleโ
import type { PickByTypes } from "type-aliases";
type StringFields = PickByTypes<User, string>;
โ Correct โ Additional exampleโ
import type { ConditionalPick } from "type-fest";
type StringFields = ConditionalPick<User, string>;
โ Correct โ Repository-wide usageโ
type DateFields = ConditionalPick<User, Date>;
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-conditional-pick": "error",
},
},
];
When not to use itโ
Disable this rule if compatibility requirements force existing alias names.
Package documentationโ
TypeFest package documentation:
Source file: source/conditional-pick.d.ts
/**
Pick keys from the shape that matches the given `Condition`.
This is useful when you want to create a new type from a specific subset of an existing type. For example, you might want to pick all the primitive properties from a class and form a new automatically derived type.
@example
```
import type {Primitive, ConditionalPick} from 'type-fest';
class Awesome {
constructor(public name: string, public successes: number, public failures: bigint) {}
run() {
// do something
}
}
type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
//=> {name: string; successes: number; failures: bigint}
```
@example
```
import type {ConditionalPick} from 'type-fest';
type Example = {
a: string;
b: string | number;
c: () => void;
d: {};
};
type StringKeysOnly = ConditionalPick<Example, string>;
//=> {a: string}
```
@category Object
*/
Rule catalog ID: R038