Skip to content
Latchkey

tsc TS2322: Type 'X' is not assignable to type 'Y' in CI

TS2322 is an assignment-compatibility error: the type on the right of an assignment (or a property value, or a returned value) is not a subtype of the declared target type, so tsc rejects it.

What this error means

tsc fails with "error TS2322: Type 'string' is not assignable to type 'number'" (or similar), often with a follow-on note about which property or member caused the mismatch.

tsc
src/config.ts:4:3 - error TS2322: Type 'string' is not assignable to type 'number'.

4   port: '8080',
    ~~~~

Common causes

The value type does not match the declared type

A string is assigned where a number is declared, or a wider union is assigned to a narrower one. tsc enforces structural assignability and rejects it.

A widened literal or a missing property in an object literal

Object literals are checked exactly; an extra or wrongly typed property makes the literal not assignable to the target interface.

How to fix it

Make the value match the target type

  1. Read the "Type X is not assignable to type Y" pair to see the exact mismatch.
  2. Convert or correct the value so its type is a subtype of the target.
  3. Re-run tsc to confirm the assignment now type-checks.
src/config.ts
// '8080' is a string; the field expects a number
const config = { port: 8080 };

Widen the target type if the broader type is intended

If both values are legitimately allowed, declare the target as a union rather than forcing a cast.

src/config.ts
type Port = number | `${number}`;

How to prevent it

  • Type config and API shapes explicitly so mismatches surface at the source.
  • Avoid as casts that paper over real assignability errors.
  • Run tsc locally before pushing so TS2322 is caught before CI.

Frequently asked questions

What causes "TS2322 "is not assignable to type""?
A string is assigned where a number is declared, or a wider union is assigned to a narrower one. tsc enforces structural assignability and rejects it.
How do I fix TS2322 "is not assignable to type"?
Make the value match the target type

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card