Special Sponsor:PromptBuilder— Fast, consistent prompt creation powered by 1,000+ expert templates.
Make your Product visible here.Contact Us

Home/TypeScript Errors/TS2554

TS2554

Expected N arguments, but got M

TypeScript TS2554 fires when you call a function with the wrong number of arguments — either too many or too few. TypeScript checks argument counts strictly against the function's parameter list.

Why This Happens

You're calling a function with more or fewer arguments than it declares. Unlike JavaScript (which silently ignores extra args or makes missing ones undefined), TypeScript enforces exact argument counts when parameters are required.

Code That Triggers TS2554

// TS2554 examples

function add(a: number, b: number): number {
  return a + b;
}

add(1, 2, 3);
// Error: Expected 2 arguments, but got 3

add(1);
// Error: Expected 2 arguments, but got 1

// Also with rest params
function log(message: string, ...extras: string[]): void {}
log(); // Error: Expected at least 1 arguments, but got 0

How to Fix TS2554

Option 1: Call the function with the correct number of arguments

add(1, 2); // correct — 2 arguments for 2 parameters

Option 2: Make extra parameters optional

function add(a: number, b: number, c?: number): number {
  return a + b + (c ?? 0);
}
add(1, 2, 3); // now OK

Option 3: Use rest parameters for variable argument counts

function sum(...nums: number[]): number {
  return nums.reduce((acc, n) => acc + n, 0);
}
sum(1, 2, 3, 4, 5); // OK

Frequently Asked Questions — TS2554

What does TS2554 mean?

TS2554 means you're calling a function with the wrong number of arguments. TypeScript enforces this at compile time — unlike JavaScript which silently accepts wrong argument counts.

How do I add optional parameters to fix TS2554?

Add ? after the parameter name: function fn(a: string, b?: number). Optional parameters can be omitted when calling the function. They must come after all required parameters.

TS2554 with 'this' parameter — how to fix?

TypeScript 'this' parameters (the first parameter named 'this') are erased at runtime and don't count as real arguments. TS2554 with a 'this' param means you're passing too many real arguments.

Can I use Function.prototype.call to bypass TS2554?

No — TypeScript still checks arguments when using .call, .apply, and .bind (with strict function types). The argument count check is on the call expression, not the runtime mechanism.

TS2554 in test mocks — how to fix?

If you're mocking a function that takes fewer arguments, the mock's type must match. Use jest.fn<ReturnType, Args>() with the correct type parameters, or cast the mock: (mockFn as jest.Mock).

Convert JavaScript to TypeScript automatically

Paste your JS code and get type-annotated TypeScript — including fixes for common type errors — in seconds.

Try the converter →

Other TypeScript Errors

From the blog

View all →