Skip to main content

prefer-type-fest-subset-of

Prefer SubsetOf from type-fest 6 for the following pattern.

Targeted pattern scopeโ€‹

An alias with two parameters whose second parameter extends the first and is returned unchanged.

What this rule reportsโ€‹

type Allowed<Domain, Selection extends Domain> = Selection;

Why this rule existsโ€‹

This helper validates the constraint while preserving the selected subtype and its literal information.

โŒ Incorrectโ€‹

type Allowed<Domain, Selection extends Domain> = Selection;

โœ… Correctโ€‹

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

type Allowed<Domain, Selection extends Domain> = SubsetOf<Domain, Selection>;

Behavior and migration notesโ€‹

The rule runs when the linted file resolves type-fest major version 6. It preserves the outer alias and its parameters. The fixer leaves comments in place and uses the configured import policy.

Package documentationโ€‹

TypeFest package documentation:

Rule catalog ID: R139

Further readingโ€‹