Skip to content

Expected 0 arguments, but got 1

Error message

                Expected N arguments, but got M
              

Quick summary

You called a function with more or fewer arguments than its signature declares. TypeScript checks argument counts at compile time.

Why this happens

  • Passing extra arguments the function doesn't accept

  • Forgetting to pass required arguments

  • The function signature doesn't include optional/rest parameters

  • Calling the wrong function overload

Minimal example

✗ Broken code
function greet(name: string): string { return `Hello, ${name}`; }
greet("Alice", 30); // too many args
✓ Fixed code
function greet(name: string, age?: number): string { return `Hello, ${name}`; }
greet("Alice", 30);

Add an optional age parameter to accept the extra argument.

How to diagnose

  • Check the function signature for the expected parameter count

  • Look for optional parameters (with ?) or rest parameters (...args)

  • Verify you're calling the correct function overload

How to fix

  • Remove extra arguments or add them to the function signature

  • Add the missing required arguments

  • Make the parameter optional with ? or add a rest parameter

  • Add a function overload that accepts the argument count you need

How to prevent

  • Use IDE tooltips to see function signatures before calling

  • Document expected arguments with JSDoc

Related Resources

Related Glossary

← Back to language