TypeScript Compiler Diagnostics
TS2558: Incorrect number of type arguments
The explicit type argument list has the wrong arity for the generic function. The two type parameters relate to two distinct arguments. Supply both type arguments or omit the list and let the compiler infer both. A type parameter default can change which arguments are required. Baseline: TypeScript 5.8.3 with the shown configuration. Reproduce in one directory and create the corrected project in another. The diagnostic can have other causes; inspect its location and message before choosing a correction. Both projects keep strict checking enabled.
Formal Syntax & Structure
typescript syntaxtypescript
TS2558 (compiler diagnostic code, not TypeScript syntax)Working Example
Example Snippettypescript
// INTENTIONALLY INVALID — reproduce// File: tsconfig.json (omit this label){ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "outDir": "dist" }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)function pair<A,B>(a:A,b:B): [A,B] { return [a,b]; }console.log(pair<number>(1,"x"));
// Run: tsc -p . --pretty false// Expected: TS2558; no output emitted.
// CORRECTED PROJECT — separate directory// File: tsconfig.json (omit this label){ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true, "outDir": "dist" }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)function pair<A,B>(a:A,b:B): [A,B] { return [a,b]; }console.log(pair<number,string>(1,"x").join(":"), pair(2,"y").join(":"));
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node dist/main.js// Expected stdout: 1:x 2:y