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

**Code:** `TS2322` · **Category:** TypeScript · **Seen on:** TypeScript

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

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)?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/typescript/ts2322-type-is-not-assignable)
