Skip to content

prefer-named-complex-return-type

Prefer a named contract for structurally complex function return types.

Why

A large inline return annotation hides a reusable domain concept and makes signatures difficult to scan.

Fix

Name the complex nested shape while preserving its generic wrappers and type parameters; reference the named contract from the return annotation.

Examples

Before — flagged Do not inline a multi-state result
src/queue.ts
export function claim():
| { state: "idle" }
| { state: "waiting"; retryAt: number }
| { state: "claimed"; id: string } {
return { state: "idle" };
}
After — preferred Name a multi-state result
src/queue.ts
type ClaimResult =
| { state: "idle" }
| { state: "waiting"; retryAt: number }
| { state: "claimed"; id: string };
export function claim(): ClaimResult {
return { state: "idle" };
}