TS2322 TypeScript Origin: On your device Last updated 13 Oct 2026

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

You assigned a value whose type doesn’t match the declared type of the variable, property or return value.

Exact message you may see is not assignable to typeType 'string | undefined' is not assignable to type 'string'error TS2322
Seen on: TypeScript

Meaning

TypeScript checks every assignment against the target type. Common cases are string | undefined assigned to string, a literal not in a union ('large' vs 'sm' | 'md'), objects missing required properties, or returning the wrong shape from a function.

Read the last lines of the message: TypeScript explains exactly which nested property is incompatible.

Common causes

  • Possibly undefined/null value assigned to a non-optional type
  • String not in a string-literal union
  • Object missing required properties or with wrong property types
  • Function returns a different shape than its declared return type

⚡ Quick fix

  1. Narrow the value first (if/??/optional chaining)
  2. Fix the type annotation if it’s too strict
  3. Use satisfies or as const for literal objects

Detailed fix by platform

TypeScript

  1. typescript
    const size: "sm" | "md" = input === "md" ? "md" : "sm";   // narrow instead of casting
    const name: string = user.name ?? "Guest";               // remove undefined
    const cfg = { mode: "dark" } as const satisfies Config;

How to diagnose

  1. Detail — The nested “Type … is not assignable” lines
  2. Source — Where does the value come from (API, props, state)?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Array to string conversion — Warning: Array to string conversion (PHP)Array to string conve…AttributeError — AttributeError: 'X' object has no attribute 'y' (Python)AttributeErrorCannot convert value of type — Swift: Cannot convert value of type 'X' to expected argument type 'Y' (iOS)Cannot convert value …Cannot use object as array — Fatal error: Uncaught Error: Cannot use object of type stdClass as array (PHP)Cannot use object as …ClassCastException — java.lang.ClassCastException: class A cannot be cast to class B (Java)ClassCastExceptionE0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308Implicit float to int — Deprecated: Implicit conversion from float 2.5 to int loses precision (PHP)Implicit float to intNG02100 — Angular: NG02100: InvalidPipeArgument: 'Unable to convert "x" into a date' for pipe 'DatePipe' (Angular)NG02100TS2322

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.