Skip to content
Latchkey

TypeScript "TS2345: Argument of type X is not assignable"

You passed a value whose type does not match the parameter the function expects. This is a genuine type error - tsc is reporting a mismatch in your code, not a configuration or environment problem.

What this error means

Type-checking fails with error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y', naming the call site. It reproduces identically every run; retrying never helps.

tsc output
src/cart.ts:18:14 - error TS2345: Argument of type 'string' is not assignable
to parameter of type 'number'.

18   addToCart(productId)
                ~~~~~~~~~

Common causes

Genuine type mismatch at the call site

The argument's type differs from the parameter type - a string where a number is expected, a wider union than allowed, or a nullable value passed where non-null is required.

Stricter types after a dependency or config bump

Upgrading a library's @types, or enabling strict/strictNullChecks, can surface a mismatch that previously compiled, so the same code now errors.

How to fix it

Make the value match the expected type

Convert or narrow the value rather than forcing it. This is real code to fix, not flake.

TypeScript
// convert explicitly at the boundary
addToCart(Number(productId))
// or narrow a union before the call
if (typeof productId === 'number') addToCart(productId)

Fix the signature if the type is wrong

  1. If the parameter type is too narrow, widen it deliberately (e.g. accept string | number).
  2. If a dependency's types changed, update your code to the new shape.
  3. Run tsc --noEmit locally to reproduce and confirm the fix.

How to prevent it

  • Run tsc --noEmit in CI to catch mismatches before they merge.
  • Enable strict so type mismatches surface early and consistently.
  • Avoid blanket as/any casts that mask real type errors.

Frequently asked questions

What causes ""TS2345: not assignable""?
The argument's type differs from the parameter type - a string where a number is expected, a wider union than allowed, or a nullable value passed where non-null is required.
How do I fix "TS2345: not assignable"?
Convert or narrow the value rather than forcing it. This is real code to fix, not flake.

Related guides

References

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