Skip to content

Argument of type 'X' is not assignable to parameter of type 'Y'

Error message

                Argument of type is not assignable to parameter of type
              

Quick summary

You passed a value to a function, but the value's type doesn't match the function's parameter type.

Why this happens

  • Passing a string where a number is expected (or vice versa)

  • Passing an object that's missing required properties

  • Passing a value from a union type without narrowing first

  • The function parameter type is too narrow for the argument

Minimal example

✗ Broken code
function double(x: number): number { return x * 2; }
double("5"); // string, not number
✓ Fixed code
function double(x: number): number { return x * 2; }
double(Number("5")); // convert to number

Convert the string to a number before passing it to the function.

How to diagnose

  • Check the function's parameter types against the argument's type

  • Look at both types in the error message

  • Check if the argument comes from a union that needs narrowing

How to fix

  • Convert the argument to the expected type

  • Widen the function's parameter type to accept the argument

  • Narrow the argument's type before passing it

  • Add a type assertion if you know the types are compatible

How to prevent

  • Use IDE tooltips to check parameter types before calling

  • Enable strict mode for thorough type checking

Related Resources

← Back to language