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.
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.
// 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
- If the parameter type is too narrow, widen it deliberately (e.g. accept
string | number). - If a dependency's types changed, update your code to the new shape.
- Run
tsc --noEmitlocally to reproduce and confirm the fix.
How to prevent it
- Run
tsc --noEmitin CI to catch mismatches before they merge. - Enable
strictso type mismatches surface early and consistently. - Avoid blanket
as/anycasts that mask real type errors.