TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'
You're passing a value into a function whose declared parameter type doesn't accept it — the shapes are incompatible, or a value could be undefined/null where the parameter doesn't allow it. Read the full error (TypeScript shows both types) to see exactly which property or branch doesn't line up, then either narrow/convert the argument or widen the parameter type.
What causes this error
This is TypeScript's most general "you're calling this wrong" error — the value you passed doesn't structurally satisfy the parameter's declared type. That can mean a missing required property, an extra incompatible property, a wrong primitive type, or a value that could be `undefined`/`null` where the parameter type doesn't include it.
The Fix
function greet(user: { name: string; age: number }) {
console.log(`Hello ${user.name}, age ${user.age}`);
}
// Wrong — missing `age`
greet({ name: 'Ada' }); // TS2345
// Fix 1 — supply the missing property
greet({ name: 'Ada', age: 36 });
// Fix 2 — if age is genuinely optional, update the parameter type
function greet(user: { name: string; age?: number }) { /* ... */ }Common causes / variations
- Passing an object literal that's missing a required property, or has a typo'd key
- Passing a possibly-`undefined` value (from an optional chain or array access) into a parameter that requires a definite value
- Passing a wider union type than the parameter accepts, e.g. `string | number` into a `string`-only parameter
Related errors
See also: TS2322 Type is not assignable, TS2769 No overload matches this call.
Comments
Loading comments...