This TypeScript error occurs when you call a function without providing any arguments, but the function requires at least one parameter. TypeScript enforces that all required parameters must be provided when calling a function to prevent runtime errors.
TypeScript's type system ensures that functions are called with the correct number and types of arguments. When you define a function with required parameters (without the `?` optional marker or default values), TypeScript enforces that you must provide those arguments when calling the function. The error "Expected at least 1 argument, but got 0" (TS2554) means you're calling a function that requires one or more parameters, but you're invoking it with an empty argument list: `myFunction()`. This is a key difference from JavaScript, where functions can be called with fewer arguments than defined—missing parameters simply become `undefined`. TypeScript prevents this by default to catch potential bugs at compile time, ensuring that functions receive the data they expect to operate correctly.
First, inspect the function definition to understand what arguments it expects:
// Function definition
function greet(name: string) {
return `Hello, ${name}!`;
}
// WRONG: Calling without arguments
const message = greet(); // Error: Expected 1 argument, but got 0
// CORRECT: Provide the required argument
const message = greet("Alice"); // OKIn VS Code, hover over the function name to see its signature and required parameters. The signature will show you exactly what the function expects.
The simplest fix is to pass the required arguments to the function:
// Function with one required parameter
function calculateDiscount(price: number) {
return price * 0.1;
}
// BEFORE: Error
const discount = calculateDiscount(); // Expected 1 argument, but got 0
// AFTER: Provide the price
const discount = calculateDiscount(100); // OK - returns 10
// Function with multiple required parameters
function createUser(name: string, email: string) {
return { name, email };
}
// BEFORE: Error
const user = createUser(); // Expected 2 arguments, but got 0
// AFTER: Provide both arguments
const user = createUser("Alice", "[email protected]"); // OKIf the parameter should be optional, mark it with ? after the parameter name:
// BEFORE: Parameter is required
function greet(name: string) {
return `Hello, ${name}!`;
}
greet(); // Error: Expected 1 argument, but got 0
// AFTER: Make parameter optional
function greet(name?: string) {
return `Hello, ${name || "Guest"}!`;
}
greet(); // OK - name is undefined, defaults to "Guest"
greet("Alice"); // OK - name is "Alice"Important: Optional parameters must come after required parameters:
// WRONG: Optional parameter before required
function createUser(email?: string, name: string) {} // Error
// CORRECT: Required parameters first, optional last
function createUser(name: string, email?: string) {} // OKDefault parameters are automatically optional and provide a fallback value:
// BEFORE: Required parameter
function createConnection(timeout: number) {
// ...
}
createConnection(); // Error: Expected 1 argument, but got 0
// AFTER: Use default value
function createConnection(timeout: number = 5000) {
// ...
}
createConnection(); // OK - timeout is 5000
createConnection(10000); // OK - timeout is 10000Default values can be complex expressions:
function fetchData(url: string = "/api/default") {
// ...
}
function createId(prefix: string = `id-${Date.now()}`) {
// ...
}Note: Do NOT use both ? and a default value—the default value already makes it optional:
// WRONG: Redundant ?
function greet(name?: string = "Guest") {} // Error
// CORRECT: Default value is enough
function greet(name: string = "Guest") {} // OKIf your function should accept zero or more arguments, use rest parameters:
// BEFORE: Fixed parameter count
function sum(a: number, b: number) {
return a + b;
}
sum(); // Error: Expected 2 arguments, but got 0
sum(1); // Error: Expected 2 arguments, but got 1
// AFTER: Use rest parameters
function sum(...numbers: number[]) {
return numbers.reduce((total, n) => total + n, 0);
}
sum(); // OK - returns 0
sum(1); // OK - returns 1
sum(1, 2, 3, 4); // OK - returns 10You can combine required parameters with rest parameters:
// First message is required, additional messages are optional
function log(firstMessage: string, ...additionalMessages: string[]) {
console.log(firstMessage);
additionalMessages.forEach(msg => console.log(" -", msg));
}
log("Hello"); // OK
log("Hello", "World", "!"); // OK
log(); // Error: Expected at least 1 argument, but got 0If a function has multiple signatures (overloads), TypeScript might be selecting one that requires arguments:
// Function with overloads
function processData(data: string): string;
function processData(): void;
function processData(data?: string): string | void {
if (data === undefined) {
console.log("No data provided");
return;
}
return data.toUpperCase();
}
// This works fine
processData(); // OK - matches second overload
processData("hello"); // OK - matches first overloadIf you see the error despite having a no-argument overload, the overload order might be wrong. Overloads are checked from top to bottom, and the implementation signature must be compatible with all overloads.
For library functions, check the type definitions to see which overloads are available:
// Example: Array.from has overloads
Array.from(); // Error: Expected at least 1 argument
Array.from([1, 2, 3]); // OK
Array.from({ length: 3 }, (_, i) => i); // OK - uses different overload### Strict Function Types
TypeScript's strictFunctionTypes compiler option affects how function parameters are checked. With strict mode enabled (recommended), TypeScript is more careful about function argument requirements:
// tsconfig.json
{
"compilerOptions": {
"strict": true, // Enables strictFunctionTypes
"strictFunctionTypes": true
}
}### Callback Functions
When passing callbacks, ensure they match the expected signature:
// Event listener expects a callback with an event parameter
button.addEventListener("click", handleClick);
// WRONG: Handler doesn't accept the event
function handleClick() { // Error when strict checking enabled
console.log("Clicked");
}
// CORRECT: Accept the event parameter (even if unused)
function handleClick(event: MouseEvent) {
console.log("Clicked");
}
// Or mark it optional if the framework allows
function handleClick(event?: MouseEvent) {
console.log("Clicked");
}### Array Methods and Required Callbacks
Some array methods require callbacks with specific signatures:
const numbers = [1, 2, 3];
// Array.map requires a callback with at least one parameter
numbers.map(); // Error: Expected 1 argument, but got 0
// Even if you ignore the parameter, you must declare it
numbers.map((item) => item * 2); // OK
numbers.map(() => 42); // OK - parameter can be omitted in arrow functions### Constructor Functions
The same rules apply to class constructors:
class User {
constructor(name: string, email: string) {
// ...
}
}
const user = new User(); // Error: Expected 2 arguments, but got 0
const user = new User("Alice", "[email protected]"); // OK
// Make constructor parameters optional if needed
class User {
constructor(name: string = "Anonymous", email?: string) {
// ...
}
}
const user = new User(); // OK### Partial Application and Currying
If you need to call a function in stages, consider using currying:
// Instead of requiring all arguments at once
function createUrl(protocol: string, domain: string, path: string) {
return `${protocol}://${domain}${path}`;
}
// Use currying to allow partial application
function createUrl(protocol: string) {
return (domain: string) => {
return (path: string) => {
return `${protocol}://${domain}${path}`;
};
};
}
const https = createUrl("https"); // OK
const site = https("example.com"); // OK
const url = site("/api/users"); // OK### Void vs Undefined
Functions that don't require arguments should explicitly define no parameters:
// UNCLEAR: Has a parameter that looks required
function initialize(config: undefined) {} // Confusing
// BETTER: No parameters at all
function initialize() {} // Clear
// Or use void in the signature
type InitFn = () => void;
const initialize: InitFn = () => {
// ...
};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