Error AtlasError Documentation and Resolution

TypeScript found an argument that is not assignable to the parameter type

error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'.

TypeScript rejected a function call because one of the provided arguments does not match the type expected by the target parameter.

TS2345build
error TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'.
  • The argument value has a different shape or primitive type than the function expects.
  • A union or generic value is broader than the accepted parameter type.
  • The function signature changed but the calling code was not updated.
  1. Read the entire diagnostic, including nested property details. Compare the parameter definition with the inferred type at the call site; inspect the selected overload for overloaded APIs.
  2. Convert the value only when that conversion matches the domain. For a number parsed from text, reject invalid input rather than passing NaN onward.
  3. Narrow unions before calling a function that accepts only one member. For example, check typeof value === "string" before passing string | number to a string-only function.
  4. For objects, supply required properties with correct types. Broaden the function contract only when its implementation really supports the additional inputs.
  5. Avoid as any and double assertions as fixes: they suppress checking without converting or validating the value. Run npx tsc --noEmit -p tsconfig.json and test the affected calls.

Pass the intended primitive type

Before

function repeatCount(count: number) {
  return count * 2;
}
repeatCount("3");

After

function repeatCount(count: number) {
  return count * 2;
}
repeatCount(3);

The string argument produces TS2345; the corrected numeric argument compiles and returns 6. If the input is user text, validate and parse it instead of asserting that the string is a number.

Narrow a union before calling

Before

function shout(value: string) { return value.toUpperCase(); }
function show(value: string | number) {
  return shout(value);
}

After

function shout(value: string) { return value.toUpperCase(); }
function show(value: string | number) {
  if (typeof value === "string") return shout(value);
  return String(value);
}

The guard proves the string branch is safe; the numeric branch has explicit behavior. This uses ordinary control-flow narrowing supported in TypeScript 5.x and 6.x.

TypeScript Handbook: Narrowing