Fixing TS2554 ‘Expected 1 arguments, but got 0’ in TypeScript
error TS2554: Expected 1 arguments, but got 0. is reported when the number of arguments you pass in a function call does not match the function's declaration. The number after Expected is how many arguments the function takes, and the number after got is how many you actually passed. Either pass the missing argument or make that parameter optional in the function, and the error goes away.
This article covers how to read the message and fix it when the type check (tsc) fails with this error, or when an editor such as VS Code shows it on the line that calls the function. It also covers the same error from useRef() with the React 19 types (@types/react 19). I reproduced the error in my test environment, copied the message as it was printed, and confirmed that the error disappears after each fix.
The test environment is Ubuntu 24.04, Node.js 22.23.4, npm 10.9.9, TypeScript 7.0.2, React 19.3.1, and @types/react 19.3.0. I did not check the screen of an editor such as VS Code. Instead, I ran the TypeScript 7 language server (tsc --lsp --stdio) directly and checked the diagnostics it returned. I did not try versions before TypeScript 7, or builds that go through a bundler such as Vite.
- 1. The code and message that trigger the error
- 2. Reading the message
- 3. The language server reports the same diagnostic
- 4. JavaScript is still emitted despite the error
- 5. Fix by passing the missing argument
- 6. If the argument is optional, make it optional in the function
- 7. Passing too many arguments: the extra argument gets the squiggle
- 8. With optional parameters, the count is shown as a range like "1-2"
- 9. When the function type sets the parameters, the type is what counts
- 10. With React 19 types, useRef() raises TS2554
- 11. resolve() in a Promise reports TS2794
The code and message that trigger the error
In an empty folder, I ran npm init -y, added "type": "module" to package.json, and installed TypeScript 7.0.2. (In the React section, I also used React and its types, installed with npm install react@19.3.1 and npm install -D @types/react@19.3.0.) The tsconfig.json created by npx tsc --init has "strict": true, and I used it without changes.
Here is src/greet.ts. It calls greet, a function that takes a name and returns a greeting, with no arguments.
function greet(name: string) {
return `こんにちは、${name}さん`;
}
console.log(greet());
Running npx tsc --noEmit printed the following single line, and the exit code was 1.
$ npx tsc --noEmit
src/greet.ts(5,13): error TS2554: Expected 1 arguments, but got 0.
Adding --pretty shows the location of the error next to the place where the missing argument is declared (colors omitted):
src/greet.ts:5:13 - error TS2554: Expected 1 arguments, but got 0.
5 console.log(greet());
~~~~~
src/greet.ts:1:16 - An argument for 'name' was not provided.
1 function greet(name: string) {
~~~~~~~~~~~~
Found 1 error in src/greet.ts:5
Reading the message
In plain terms, the message says that one argument is required but none was passed. Read as English, 1 arguments has an extra s, but TypeScript prints it this way.
Expected 1 arguments: the number of arguments the function takesbut got 0: the number of arguments actually passed in the callAn argument for 'name' was not provided.: the name of the missing argument (name) and where it is declared (line 1 ofsrc/greet.ts)
The squiggle is under the name of the function being called (greet on line 5). The following An argument for ... was not provided. line tells you which argument is missing.
The language server reports the same diagnostic
I opened the same src/greet.ts with the TypeScript 7 language server (tsc --lsp --stdio). It returned one diagnostic with the same text as tsc. The output below comes from a check script I wrote. It lists the diagnostics and hover result that were returned, with lines and columns counted from 1.
diagnostics (1):
5:13-5:18 severity=1 source=ts code=2554 Expected 1 arguments, but got 0.
related src/greet.ts:1:16 An argument for 'name' was not provided.
hover 5:13: function greet(name: string): string
The diagnostic range 5:13-5:18 covers the five characters of greet on line 5. In the definition of DiagnosticSeverity in the Language Server Protocol specification, severity 1 means error. The related line has the same content as tsc's An argument for 'name' was not provided. Hovering over greet shows function greet(name: string): string, which also lets you confirm the name and type of the argument.
JavaScript is still emitted despite the error
tsc writes JavaScript files even when the type check reports errors. When I removed --noEmit and wrote the output to dist, the same TS2554 appeared and the exit code was 2, but dist/greet.js was still created. As the tsconfig reference for noEmitOnError says, the default for the setting that stops output on errors is false.
Running the emitted JavaScript with Node.js printed the following:
$ node dist/greet.js
こんにちは、undefinedさん
In JavaScript, a missing argument becomes undefined. This does not cause a runtime error, so if you run code without passing the type check, you won't notice the mistake until you look at the output.
Fix by passing the missing argument
If the function needs the argument, pass it at the call site. I changed line 5 as follows. In the test, I put the fixed version in a separate file.
console.log(greet("猫の手"));
npx tsc --noEmit printed nothing and exited with 0, and the language server returned 0 diagnostics. When emitted and run, it prints こんにちは、猫の手さん.
If the argument is optional, make it optional in the function
If the argument is not always passed, change the function declaration. As the TypeScript Handbook section on optional parameters explains, adding ? after the parameter name lets you call the function without that argument. When it is omitted, its value is undefined, so decide on a fallback value inside the function.
function greet(name?: string) {
return `こんにちは、${name ?? "ゲスト"}さん`;
}
console.log(greet());
console.log(greet("猫の手"));
Even with greet() as it is, npx tsc --noEmit exits with 0. Running it printed the following:
こんにちは、ゲストさん
こんにちは、猫の手さん
A default value also makes an argument optional:
function greet(name = "ゲスト") {
return `こんにちは、${name}さん`;
}
npx tsc --noEmit also exits with 0, and the run output is the same as with ?. Hovering over greet on line 1 shows function greet(name?: string): string in the language server. From the caller's side, an argument with a default value looks the same as one marked with ?.
Which fix to use depends on whether the function really needs the argument. If you add ? just to silence the error, the type check can no longer catch the case where the argument was actually forgotten.
Passing too many arguments: the extra argument gets the squiggle
A mismatch is not only about passing too few. In src/greet-extra.ts, I passed two arguments to the same greet, and the message was:
src/greet-extra.ts:5:26 - error TS2554: Expected 1 arguments, but got 2.
5 console.log(greet("猫の手", "さま"));
~~~~
Found 1 error in src/greet-extra.ts:5
This time it says got 2, and the squiggle is under the extra second argument "さま", not the function name. The language server's diagnostic range was also 5:26-5:30, which is the "さま" part. If the extra argument is not needed, remove it. If it is needed, add it to the function declaration.
With optional parameters, the count is shown as a range like "1-2"
For a function with an optional argument, the accepted count is shown as a range. I called label, which has an optional second parameter color, once with no arguments and once with three.
function label(text: string, color?: string) {
return color ? `[${color}] ${text}` : text;
}
console.log(label());
console.log(label("注意", "red", "bold"));
src/label.ts(5,13): error TS2554: Expected 1-2 arguments, but got 0.
src/label.ts(6,32): error TS2554: Expected 1-2 arguments, but got 3.
Expected 1-2 arguments means "from 1 to 2." The smaller number is the minimum that must be passed, and the larger number is the maximum that can be passed.
When the function type sets the parameters, the type is what counts
With callbacks and similar cases, the function type may be decided first. I assigned a function that takes no arguments to SaveHandler, a type whose function takes id, and then called it with no arguments.
type SaveHandler = (id: number) => void;
const onSave: SaveHandler = () => {
console.log("saved");
};
onSave();
src/handler.ts(7,1): error TS2554: Expected 1 arguments, but got 0.
Even though the function body doesn't use any argument, the call is checked against the SaveHandler type. Calling onSave(1); with id made the error disappear. Assigning a function with fewer parameters to a function type with more parameters (line 3) is not an error by itself. As the callback section of the Handbook explains, JavaScript ignores extra arguments, so TypeScript allows this.
With React 19 types, useRef() raises TS2554
With @types/react 19, calling useRef() with no arguments produces this error.
import { useRef } from "react";
export function Box() {
const ref = useRef<HTMLDivElement>();
return <div ref={ref}>box</div>;
}
src/Box.tsx:4:15 - error TS2554: Expected 1 arguments, but got 0.
4 const ref = useRef<HTMLDivElement>();
~~~~~~
node_modules/@types/react/index.d.ts:1744:24 - An argument for 'initialValue' was not provided.
1744 function useRef<T>(initialValue: T): RefObject<T>;
~~~~~~~~~~~~~~~
Found 1 error in src/Box.tsx:4
The missing argument is initialValue, the initial value of the ref. Its declaration is in the @types/react type definitions, not in your own code. The React 19 upgrade guide says that the argument became required in the useRef type. For a ref that holds a DOM element, pass null:
const ref = useRef<HTMLDivElement>(null);
With this change, npx tsc --noEmit exits with 0, and the language server returned 0 diagnostics. The hover now shows a return type of React.RefObject<HTMLDivElement | null>.
resolve() in a Promise reports TS2794
Calling resolve() with no arguments inside new Promise produces an error with the same text. The code is TS2794, though, and a hint follows it.
function wait(ms: number) {
return new Promise<number>((resolve) => {
setTimeout(() => resolve(), ms);
});
}
await wait(100);
src/wait.ts(3,22): error TS2794: Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?
As the hint suggests, for a Promise that only waits and does not produce a value, set the type argument to Promise<void>:
function wait(ms: number) {
return new Promise<void>((resolve) => {
setTimeout(() => resolve(), ms);
});
}
await wait(100);
console.log("100ms 待ちました");
The error goes away, and when emitted and run, it printed 100ms 待ちました. The TypeScript 4.1 release notes say that the resolve argument is no longer optional and that writing Promise<void> lets you call it with no arguments. The example in the release notes shows TS2554, but in the test environment with TypeScript 7.0.2 it was TS2794. For a Promise that produces a value, pass the value, as in resolve(value).




