TS2554Semantic Error
Since TS 1.0

Fix TS2554: Wrong Number of Arguments

Learn why TypeScript throws TS2554 when calling functions with the wrong number of arguments, and how to fix argument count mismatches.

error TS2554: Expected N arguments, but got M

What This Error Means

TS2554 fires when you call a function with the wrong number of arguments. Unlike JavaScript, which silently ignores extra arguments and sets missing ones to undefined, TypeScript enforces that function calls match the declared parameter count exactly.

This catch is valuable because passing too many arguments usually means you're calling the wrong function, and passing too few often leads to undefined sneaking in where a real value was expected.

// The general shape of the error:
// Expected 2 arguments, but got 1.
// Expected 1 arguments, but got 3.

Common Causes

1. Forgetting a Required Argument

The most common case — you forgot to pass one of the required parameters.

// ❌ Broken
function createInvoice(customerId: string, amount: number, currency: string) {
  return { customerId, amount, currency }
}
 
const invoice = createInvoice("cust_123", 99.99)
//              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Error: Expected 3 arguments, but got 2.
// ✅ Fixed — pass all required arguments
const invoice = createInvoice("cust_123", 99.99, "USD")

2. Passing Extra Arguments

Calling a function with more arguments than it accepts. This often happens after refactoring when a parameter was removed but call sites weren't updated.

// ❌ Broken
function sendNotification(userId: string, message: string) {
  // sends the notification
}
 
sendNotification("user_456", "Your order shipped!", "email", true)
//                                                  ~~~~~~~  ~~~~
// Error: Expected 2 arguments, but got 4.
// ✅ Fixed — pass only the expected arguments
sendNotification("user_456", "Your order shipped!")

3. API or Library Changes

After updating a dependency, function signatures may change. Parameters get added, removed, or reordered.

// ❌ Broken — the library updated and added a required 'options' parameter
import { connectDatabase } from "my-db-lib"
 
// Old API: connectDatabase(url)
// New API: connectDatabase(url, options)
connectDatabase("postgres://localhost:5432/mydb")
// Error: Expected 2 arguments, but got 1.
// ✅ Fixed — pass the new required parameter
connectDatabase("postgres://localhost:5432/mydb", { ssl: true })

How to Fix It

  1. Pass the correct number of arguments. Check the function signature and provide all required parameters:

    function greet(name: string, greeting: string) { /* ... */ }
    greet("Alice", "Hello") // correct: 2 arguments for 2 parameters
  2. Make parameters optional. If a parameter isn't always needed, add ? after its name:

    function greet(name: string, greeting?: string) {
      return `${greeting ?? "Hi"}, ${name}!`
    }
    greet("Alice")          // works: greeting defaults to "Hi"
    greet("Alice", "Hello") // also works
  3. Use default parameter values. This makes the parameter optional while providing a fallback:

    function createUser(name: string, role: string = "viewer") {
      return { name, role }
    }
    createUser("Bob")           // { name: "Bob", role: "viewer" }
    createUser("Bob", "admin")  // { name: "Bob", role: "admin" }
  4. Use rest parameters for variable arguments. When the number of arguments is genuinely variable:

    function logMessages(level: string, ...messages: string[]) {
      messages.forEach((msg) => console.log(`[${level}] ${msg}`))
    }
    logMessages("info", "Server started", "Listening on port 3000")
  5. Check for function overloads. Some functions have multiple signatures. Make sure you're matching one of the declared overloads:

    function createElement(tag: "div"): HTMLDivElement
    function createElement(tag: "span"): HTMLSpanElement
    function createElement(tag: string): HTMLElement
    function createElement(tag: string) { /* ... */ }

FAQ

What causes TS2554?

TS2554 occurs whenever a function call doesn't match the expected number of parameters. TypeScript counts required parameters (those without ? or default values) and total parameters (including optional ones) to determine the valid range. If your call falls outside that range — too few or too many arguments — you get this error. This is one of TypeScript's most fundamental checks, catching a category of bugs that JavaScript silently allows.

How do I fix expected N arguments but got M?

Start by looking at the function's signature to understand what it expects. If you're passing too few arguments, add the missing ones. If you're passing too many, remove the extras or check whether you're calling the right function. If the function's API should be more flexible, modify its signature to use optional parameters, default values, or rest parameters as appropriate.

How do I make function parameters optional?

There are two ways to make parameters optional. First, add ? after the parameter name: function search(query: string, limit?: number). The parameter's type becomes number | undefined inside the function body. Second, provide a default value: function search(query: string, limit: number = 10). With a default, the parameter is optional at the call site but always has a value inside the function. Optional parameters must come after all required parameters in the signature.

Related Errors

Share this reference

Stay Updated

Get the latest TypeScript tips, tutorials, and course updates delivered straight to your inbox.

No spam, unsubscribe at any time.