Skip to main content

prefer-type-fest-function

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

Targeted pattern scopeโ€‹

An alias with a single rest parameter and a built-in Promise result, or an unrestricted rest signature returning unknown.

What this rule reportsโ€‹

type Loader<Args extends readonly unknown[], Result> = (...args: Args) => Promise<Result>;

Why this rule existsโ€‹

The rule distinguishes AnyFunction, AnyAsyncFunction and AsyncFunction. Named parameters, function-local generics, and return types that depend on a parameter need to keep their original scope.

โŒ Incorrectโ€‹

type Loader<Args extends readonly unknown[], Result> = (...args: Args) => Promise<Result>;

โœ… Correctโ€‹

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

type Loader<Args extends readonly unknown[], Result> = AsyncFunction<Args, Result>;

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: R143

Further readingโ€‹