Skip to content
Sarj Code Standards

no-contradictory-overload-return

Preserve the input/result relationship promised by literal overloads.

Why

TypeScript checks an overload implementation against an overall envelope, without proving each input/result relationship. A function can compile while returning the opposite domain variant for every advertised literal input.

Fix

Return the variant promised for each input. Prefer a checked case map or separate variant-specific operations when that makes the relationship explicit; retain overloads required by public APIs.

Examples

Before — flagged Do not swap domain variants behind overloads
src/load.ts
function load(kind: "text"): { kind: "text" };
function load(kind: "count"): { kind: "count" };
function load(kind: "text" | "count"): { kind: "text" | "count" } {
return kind === "text" ? { kind: "count" } : { kind: "text" };
}
After — preferred Match each literal input with its result
src/load.ts
function load(kind: "text"): { kind: "text" };
function load(kind: "count"): { kind: "count" };
function load(kind: "text" | "count"): { kind: "text" | "count" } {
return kind === "text" ? { kind: "text" } : { kind: "count" };
}

References