Looking for a structured path? Browse all TypeScript lessons.

Maintained by
Learning Platform content team
Reviewed by
Learning Platform source and executable-example contract

Fix TypeScript TS2322: type is not assignable

TS2322 says the value on the right side of an assignment is not safe for the type on the left. Read the diagnostic as: source type cannot satisfy target type.

Reproduce a common strict-null error

type User = { name?: string };

const user: User = {};
const label: string = user.name;
// Type 'string | undefined' is not assignable to type 'string'.

The fix is to handle the missing case, not to assert it away:

type User = { name?: string };
const user: User = {};
const label: string = user.name ?? "Anonymous";
console.log(label);

Expected output:

Anonymous

Literal widening

type Status = "draft" | "published";
const record = { status: "draft" };
const status: Status = record.status; // TS2322: string is too wide

Preserve the literal at its source:

type Status = "draft" | "published";
const record = { status: "draft" } as const;
const status: Status = record.status;
console.log(status);

For mutable objects, annotate the property instead of freezing everything. For external JSON, validate the runtime value before assigning it to a trusted type.

Object shape mismatch

If the message lists a missing property, either provide it or make it optional only when the domain really allows absence. If it lists an incompatible nested property, follow the indented diagnostic to the deepest mismatch.

Failure mode: as Target

A type assertion suppresses the evidence rather than changing the runtime value. user.name as string can still be undefined. Narrow, default, or validate instead.

Compare TS2322 with the call-site version in our TS2345 guide, run a minimal reproduction in the TypeScript playground, and practice type narrowing.

Official references