This TypeScript error occurs when you call a function with more arguments than it expects. The compiler is enforcing function signature matching to prevent bugs from passing unnecessary or incorrect arguments.
TypeScript enforces strict function signature checking to catch bugs at compile-time. When a function is defined with no parameters (or a specific number), TypeScript ensures every call to that function matches the signature exactly. The error "Expected 0 arguments, but got 1" means you're calling a function that takes zero parameters, but you're passing one or more arguments. This is different from JavaScript, which allows you to call functions with any number of arguments—extra arguments are simply ignored at runtime. TypeScript's strict checking prevents common bugs where: 1. **Wrong function reference**: You're calling the wrong overload or function variant 2. **API changes**: The function signature changed but call sites weren't updated 3. **Type definition mismatches**: Third-party library types don't match actual implementation This error commonly appears when using libraries with complex type definitions (React, Redux, i18next) or when upgrading packages that changed function signatures.
First, check the actual definition of the function you're calling. Look for how many parameters it expects:
// Function defined with no parameters
function greet() {
return "Hello, World!";
}
// WRONG: Calling with an argument
greet("Bobby"); // Error TS2554: Expected 0 arguments, but got 1
// CORRECT: Call with no arguments
greet();Use your IDE's "Go to Definition" (F12 in VS Code) to jump to the function and inspect its signature. Sometimes you might be calling the wrong function with a similar name.
If you need to pass arguments, update the function definition to accept parameters:
// BEFORE: No parameters
function greet() {
return "Hello, World!";
}
// AFTER: Add parameter
function greet(name: string) {
return `Hello, ${name}!`;
}
// Now this works
greet("Bobby");For optional parameters, add a question mark:
function greet(name?: string) {
return name ? `Hello, ${name}!` : "Hello, World!";
}
// Both work now
greet(); // "Hello, World!"
greet("Bobby"); // "Hello, Bobby!"If the function is defined via a type alias or interface, update the type to match your usage:
// BEFORE: Type says no arguments
type GreetFunction = () => string;
const greet: GreetFunction = () => {
return "Hello, World!";
};
greet("Bobby"); // Error: Expected 0 arguments, but got 1
// AFTER: Update type to accept parameter
type GreetFunction = (name: string) => string;
const greet: GreetFunction = (name) => {
return `Hello, ${name}!`;
};
greet("Bobby"); // Works!For interfaces:
interface Greeter {
greet: (name: string) => string; // Updated to accept parameter
}
const myGreeter: Greeter = {
greet: (name) => `Hello, ${name}!`,
};If the function genuinely doesn't need arguments, remove them from the call site:
function getCurrentTimestamp() {
return Date.now();
}
// WRONG: Passing unnecessary argument
const time = getCurrentTimestamp(new Date()); // Error
// CORRECT: No arguments needed
const time = getCurrentTimestamp();This commonly happens when refactoring code or when a function signature changes but not all call sites are updated.
If you're using a third-party library and getting this error, the type definitions might be incorrect or outdated:
// Example with Redux Toolkit createAsyncThunk
// Old versions might have incorrect types
import { createAsyncThunk } from '@reduxjs/toolkit';
// If you see: Expected 0 arguments, but got 1
// Try updating the package:# Update to latest version
npm update @reduxjs/toolkit
# or
npm install @reduxjs/toolkit@latest
# Also update type definitions if separate
npm update @types/your-libraryCheck the library's GitHub issues for known typing problems. Search for: "Expected 0 arguments" + library name.
Sometimes TypeScript's type inference creates unexpected function signatures. Explicitly specify generic types:
// Generic function that might infer incorrectly
function identity<T>(value: T): T {
return value;
}
// TypeScript might infer: () => void instead of (x: number) => number
const fn = identity((x: number) => x * 2);
// SOLUTION: Explicitly specify the generic type
const fn = identity<(x: number) => number>((x) => x * 2);
// Or use type assertion
const fn = identity(((x: number) => x * 2) as (x: number) => number);For compose/HOC patterns:
import { compose } from 'redux';
// If compose has type issues, explicitly type the result
type MyComponentProps = { name: string };
const EnhancedComponent = compose<React.FC<MyComponentProps>>(
withRouter,
connect(mapStateToProps)
)(MyComponent);### Function Overloads and Signatures
TypeScript allows function overloads where multiple signatures exist for one function. The error might occur if you're matching the wrong overload:
// Function with multiple overloads
function format(value: number): string;
function format(value: string, template: string): string;
function format(value: number | string, template?: string): string {
if (typeof value === "number") {
return value.toString();
}
return template ? template.replace("{}", value) : value;
}
// Calling the first overload (0 args after value)
format(42); // OK
// Calling the second overload (1 arg after value)
format("test", "Value: {}"); // OK
// Error: No overload matches
format(42, "template"); // Wrong - number overload expects 0 additional argsAlways check which overload you're targeting. Use your IDE's IntelliSense to see all available signatures.
### React Hooks and Component Props
Common in React when passing props to components or using hooks:
// Component defined with no props
const Button: React.FC = () => {
return <button>Click me</button>;
};
// Error: Expected 0 arguments, but got 1
<Button onClick={handleClick} />
// FIX: Add props interface
interface ButtonProps {
onClick: () => void;
}
const Button: React.FC<ButtonProps> = ({ onClick }) => {
return <button onClick={onClick}>Click me</button>;
};
// Now works
<Button onClick={handleClick} />For hooks like useEffect:
// WRONG: useEffect with no cleanup function
useEffect(() => {
// effect
})(); // Error: calling the effect function
// CORRECT: useEffect returns cleanup, don't call it
useEffect(() => {
// effect
});### Default Parameters vs. Optional Parameters
Understanding the difference helps prevent this error:
// Optional parameter (can be omitted)
function greet(name?: string) {
return name || "Guest";
}
// Default parameter (has a default value)
function greet(name: string = "Guest") {
return name;
}
// Both allow calling with 0 or 1 argument
greet(); // OK
greet("Bobby"); // OKBut type annotations are different:
// Type with optional parameter
type GreetFn = (name?: string) => string;
// Type with required parameter (can't call with 0 args)
type GreetFn = (name: string) => string;### Variance in Function Types
TypeScript function types are contravariant in parameters. More permissive functions can't be assigned to stricter types:
type NoArgs = () => void;
type OneArg = (x: number) => void;
let fn1: NoArgs = () => {};
let fn2: OneArg = (x) => {};
// Error: can't assign function that expects arg to one that doesn't
fn1 = fn2; // Error
// OK: can assign no-arg function to one-arg type (extra params ignored)
fn2 = fn1; // OKThis explains errors in callback scenarios where TypeScript enforces strict matching.
Function expression requires a return type
Function expression requires a return type
Value of type 'string | undefined' is not iterable
How to fix "Value is not iterable" in TypeScript
Type 'undefined' is not assignable to type 'string'
How to fix "Type undefined is not assignable to type string" in TypeScript
Type narrowing from typeof check produces 'never'
How to fix "Type narrowing produces never" in TypeScript
Type parameter 'T' has conflicting constraints
How to fix "Type parameter has conflicting constraints" in TypeScript