TS2322: Type 'X' is not assignable to type 'Y'

Typescript·Sep 13, 2026·beginner·
Quick answer

You're assigning a value to a variable, property, or return position whose declared type doesn't structurally accept it. This is the assignment-context sibling of TS2345 (which fires on function arguments) — the fix is the same idea: either correct the value's shape, or widen the declared type if the narrower value should genuinely be allowed.

What causes this error

TS2322 fires anywhere a value is assigned into a position with a declared type — a variable with an explicit annotation, an object property, a function's return type, or a React prop — and the value's actual type doesn't satisfy it. It's structurally the same check as TS2345, just at an assignment site instead of a call site.

The Fix

interface Config {
  mode: 'light' | 'dark';
}

// Wrong — 'system' isn't part of the 'light' | 'dark' union
const config: Config = { mode: 'system' }; // TS2322

// Fix 1 — use a value the type actually allows
const config: Config = { mode: 'dark' };

// Fix 2 — if 'system' is a legitimate value, widen the type
interface Config {
  mode: 'light' | 'dark' | 'system';
}

Common causes / variations

  • A string literal that doesn't match a union type's exact allowed values (case-sensitive, no typos)
  • Returning a value from a function whose inferred/declared return type is narrower than what's actually returned
  • Assigning `null`/`undefined` into a type that doesn't include them (common right after removing `strictNullChecks` exceptions)

Related errors

See also: TS2345 Argument not assignable, TS2532 Object is possibly undefined.

Was this fix helpful?

Comments

Loading comments...