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.
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
- Narrow the value first (if/??/optional chaining)
- Fix the type annotation if it’s too strict
- Use satisfies or as const for literal objects
Detailed fix by platform
TypeScript
- 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
- Detail — The nested “Type … is not assignable” lines
- 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:
Similar errors
Other ways to find it
🧠 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.
Report a correction or suggest an improvement
Last updated 7 Oct 2026