- Error
- Reported by the type checker
TS2345
Argument of type '{0}' is not assignable to parameter of type '{1}'.
A function is called with an argument whose type doesn't match the parameter. Convert the argument, or fix the parameter's type.
What it means
Each argument must be assignable to the type of the parameter it fills. When it isn't, the message names both types; for objects, extra indented lines point to the property that differs. For overloaded functions the error is TS2769 instead.
Example
function square(n: number) {
return n * n;
}
export const s = square("4");
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(5,25): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Convert the argument:
square(Number("4")). - Narrow a union argument first (for example check for
undefined). - If the function should accept more, widen the parameter type.