Skip to content

noMisleadingReturnType

biome.json
{
"linter": {
"rules": {
"nursery": {
"noMisleadingReturnType": "error"
}
}
}
}

Detect return type annotations that are misleadingly wider than what the implementation actually returns.

Reports when a function’s explicit return type annotation is wider than what TypeScript would infer from the implementation, hiding precise types from callers.

invalid.ts
function getStatus(b: boolean): string { if (b) return "loading"; return "idle"; }
/invalid.ts:1:31 lint/nursery/noMisleadingReturnType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The return type annotation is wider than what the function actually returns.

> 1 │ function getStatus(b: boolean): string { if (b) return “loading”; return “idle”; }
^^^^^^^^
2 │

A wider return type hides the precise types that callers could rely on.

Consider using “loading” | “idle” as the return type.

This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9810 for more information or to report possible bugs.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

invalid2.ts
function getCode(ok: boolean): number { if (ok) return 200; return 404; }
/invalid2.ts:1:30 lint/nursery/noMisleadingReturnType ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The return type annotation is wider than what the function actually returns.

> 1 │ function getCode(ok: boolean): number { if (ok) return 200; return 404; }
^^^^^^^^
2 │

A wider return type hides the precise types that callers could rely on.

Consider using 200 | 404 as the return type.

This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/9810 for more information or to report possible bugs.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

function getStatus() { return "loading"; }
function run(): void { return; }