Skip to main content

prefer-type-fest-guarded-type

Prefer GuardedType from type-fest 6. Extract the type narrowed by a predicate whose first parameter holds the tested value.

Targeted pattern scopeโ€‹

A type alias checks its own bare parameter against a predicate function with a required any first parameter and an any[] rest parameter. The predicate narrows that first parameter to an unconstrained inferred type.

What this rule reportsโ€‹

The true branch returns the inferred type. The false branch returns never. Renaming the input, rest parameter, or inferred type preserves the match.

Why this rule existsโ€‹

The rest parameter matters for guards with additional required arguments. A naked check parameter distributes over unions of guards and discards members whose signatures return plain booleans.

โŒ Incorrectโ€‹

type ExtractGuard<F> = F extends (item: any, ...args: any[]) => item is infer G
? G
: never;

โœ… Correctโ€‹

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

type ExtractGuard<F> = GuardedType<F>;

Behavior and migration notesโ€‹

The rule skips one-parameter signatures, constrained inference, assertions, and checks against concrete types. A comment inside the matched expression or a conflicting local name prevents an automatic edit.

Package documentationโ€‹

TypeFest package documentation:

Rule catalog ID: R148

Further readingโ€‹