Skip to content
Latchkey

tsc TS2345: Argument of type 'X' is not assignable to parameter of type 'Y' in CI

TS2345 is the call-site version of an assignability error: the argument you passed has a type that is not assignable to the declared parameter type, so the call is rejected at type-check.

What this error means

tsc fails with "error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'", often with a note pointing at the specific property that does not match.

tsc
src/api.ts:9:14 - error TS2345: Argument of type 'string | undefined' is not assignable to
parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.

9   sendId(req.id);
               ~~~~~~

Common causes

The argument type is wider than the parameter

A value typed string | undefined cannot be passed where string is required; the undefined arm is not assignable.

A structural mismatch in an object argument

The argument object is missing a required property or has a property of the wrong type, so it is not assignable to the parameter interface.

How to fix it

Narrow or validate the argument before the call

  1. Read the "Type ... is not assignable" follow-on to see the exact gap.
  2. Guard out the disallowed arm (for example undefined) before calling.
  3. Re-run tsc to confirm the argument now matches the parameter.
src/api.ts
if (req.id !== undefined) {
  sendId(req.id);
}

Adjust the parameter type if the wider type is valid

If the function should accept the broader type, declare the parameter to match rather than casting at the call site.

src/api.ts
function sendId(id: string | undefined) { /* ... */ }

How to prevent it

  • Type function parameters precisely so call sites are checked.
  • Narrow nullable values before passing them as required arguments.
  • Avoid as casts that hide real argument mismatches.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →