TS2367: This comparison appears to be unintentional because the types have no overlap (TypeScript) — how to fix
error TS2367: This comparison appears to be unintentional because the types '"admin" | "user"' and '"guest"' have no overlap.
Quick fix: Fix the value or the type so they can match: correct the literal (role === "admin"), add the missing member to the union type, or convert before comparing (Number(input) === 5). If an earlier if/return already narrowed the variable, remove the dead comparison.
What it means
TypeScript checks that both sides of an equality comparison share at least one possible value. If the types have no overlap, the comparison can never be true, which almost always points to a bug, so the compiler reports TS2367.
type Role = "admin" | "user";
function check(role: Role) {
if (role === "guest") { } // TS2367: no overlap between Role and "guest"
}
Cause 1: typo or missing union member
The literal does not exist in the union. Either fix the spelling or, if "guest" is a real value, add it to the type:
type Role = "admin" | "user" | "guest";
This also catches casing mistakes ("Admin" vs "admin").
Cause 2: comparing a number with a string
const id: number = 5;
const fromUrl: string = params.get("id") ?? "";
if (id === fromUrl) { } // TS2367: number and string
Convert one side explicitly:
if (id === Number(fromUrl)) { }
// or
if (String(id) === fromUrl) { }
Form inputs, URL params and localStorage values are always strings.
Cause 3: narrowing already excluded the value
Control-flow analysis remembers earlier checks:
function label(status: "open" | "closed") {
if (status === "open") return "Open";
if (status === "open") { } // TS2367: status is "closed" here
return "Closed";
}
Remove the dead branch, or restructure the logic. In a chain like if (x !== "a" || x !== "b"), the second test has the same problem and the condition is always true: you probably meant &&.
Cause 4: comparing different enums or enum vs literal
enum Color { Red, Green }
enum Size { Small, Large }
if (color === Size.Small) { } // TS2367
Compare against the right enum. With string enums, comparing to a plain string literal also triggers this error; use the enum member (Status.Active) instead of "active".
Cause 5: the declared type is too narrow
If a variable was inferred as a literal type, e.g. const mode = "dev", then mode === "prod" is always false. Annotate it with the wider type:
const mode: "dev" | "prod" = process.env.NODE_ENV === "production" ? "prod" : "dev";
Avoid silencing the error with as any: the compiler is pointing at a condition that does not do what you think.
Last updated 2026-12-02.