TS2314
TypeScriptERRORNotableType SystemHIGH confidence
Generic type requires type arguments
What this means
A generic type was used without providing the necessary type arguments.
Why it happens
- 1Using a generic type like 'Array' or 'Promise' without specifying the type it holds.
- 2Defining a variable with a generic interface but omitting the type parameter.
- 3Forgetting to pass a type to a generic class instantiation.
How to reproduce
A generic 'Array' type is used without a type argument.
trigger — this will error
trigger — this will error
let items: Array;
expected output
error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
Fix 1
Provide the type argument
WHEN The type of the items is known.
Provide the type argument
let items: Array<string>;
Why this works
Specifying the type argument satisfies the generic type's requirement.
Fix 2
Use shorthand array syntax
WHEN Working with arrays.
Use shorthand array syntax
let items: string[];
Why this works
This is a more common and readable syntax for declaring typed arrays.
What not to do
✕ Use 'Array<any>'
This negates the type safety benefits of using a generic collection by allowing items of any type.
Sources
Official documentation ↗
microsoft/TypeScript src/compiler/diagnosticMessages.json
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev