Skip to main content

prefer-type-fest-async-return-type

Require TypeFest AsyncReturnType<T> over Awaited<ReturnType<T>> compositions.

Targeted pattern scopeโ€‹

This rule targets nested built-in utility compositions used for async return extraction.

What this rule reportsโ€‹

  • Type references shaped like Awaited<ReturnType<T>>.

Why this rule existsโ€‹

AsyncReturnType<T> is easier to scan and more explicit about intent than stacking two utility types. Using the TypeFest alias also keeps async return extraction conventions consistent across the codebase.

โŒ Incorrectโ€‹

type Output = Awaited<ReturnType<typeof fetchData>>;

โœ… Correctโ€‹

type Output = AsyncReturnType<typeof fetchData>;

Behavior and migration notesโ€‹

  • AsyncReturnType<F> is the canonical replacement for Awaited<ReturnType<F>> in function-return extraction.
  • This rule targets the exact composition shape rather than all uses of Awaited or ReturnType.
  • Keep direct built-in utilities when you intentionally need non-function or partially-unwrapped patterns.

Additional examplesโ€‹

โŒ Incorrect โ€” Additional exampleโ€‹

type Data = Awaited<ReturnType<typeof fetchUser>>; // Repeated built-in composition

โœ… Correct โ€” Additional exampleโ€‹

type Data = AsyncReturnType<typeof fetchUser>;

โœ… Correct โ€” Repository-wide usageโ€‹

type MutationResult = AsyncReturnType<typeof saveSettings>;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-async-return-type": "error",
},
},
];

When not to use itโ€‹

Disable this rule if explicit built-in utility composition is required for local style consistency.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/async-return-type.d.ts

/**
Unwrap the return type of a function that returns a `Promise`.

There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.

@example
```ts
import type {AsyncReturnType} from 'type-fest';

declare function asyncFunction(): Promise<{foo: string}>;

// This type resolves to the unwrapped return type of `asyncFunction`.
type Value = AsyncReturnType<typeof asyncFunction>;
//=> {foo: string}

declare function doSomething(value: Value): void;

const value = await asyncFunction();
doSomething(value);
```

@category Async
*/

Rule catalog ID: R037

Further readingโ€‹

Adoption resourcesโ€‹