- Error
- Reported by the type checker
TS2558
Expected {0} type arguments, but got {1}.
A generic function or type gets more or fewer explicit type arguments than it has type parameters. Pass the right number.
What it means
When you write f<A, B>(...) explicitly, the number of type arguments must fit the function's type parameters (type parameters with defaults may be left out).
Example
function first<T>(items: T[]): T | undefined {
return items[0];
}
export const x = first<string, number>(["a"]);
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(4,23): error TS2558: Expected 1 type arguments, but got 2.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Pass as many type arguments as the function declares.
- Or leave them out and let them be inferred:
first(["a"]).