Skip to content

Generic type requires 1 type argument(s)

Error message

                Generic type requires N type argument(s)
              

Quick summary

You used a generic type or function without providing the required type parameter(s). TypeScript requires explicit type arguments when they cannot be inferred.

Why this happens

  • Using a generic type as a type annotation without type arguments

  • Calling a generic function where type parameters can't be inferred

  • Using a generic class without specifying type arguments

  • Type inference fails due to ambiguous or missing context

Minimal example

✗ Broken code
const items: Array = [1, 2, 3]; // Array requires a type argument
✓ Fixed code
const items: Array<number> = [1, 2, 3];

Provide the type argument: Array<number>.

How to diagnose

  • Check if the type or function has generic parameters

  • Determine if TypeScript can infer the type arguments from usage

  • Look at the error message for the expected number of type arguments

How to fix

  • Provide explicit type arguments: Array<string> or myFunc<string>(arg)

  • Provide a value that allows TypeScript to infer the type parameter

  • Set a default type parameter: <T = string> in the declaration

How to prevent

  • Use default type parameters when a sensible default exists

  • Design APIs so type parameters can be inferred from arguments

Related Resources

Related Glossary

← Back to language