Menu

← Back to missingType.*

Error Identifier: missingType.generics

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

/**
 * @template T
 */
class Collection
{
	/** @param T $item */
	public function add($item): void {}
}

class UserRepository
{
	/** @return Collection */ // ERROR: Class UserRepository has @return tag with generic class Collection but does not specify its types: T
	public function getUsers(): Collection
	{
		return new Collection();
	}
}

Why is it reported? #

A generic class is used without specifying its type parameters. Generic classes (those with @template tags) expect type arguments to be provided when they are referenced. Without type arguments, PHPStan cannot properly track the types flowing through the generic class, reducing the effectiveness of type checking.

This is similar to using array instead of array<string, int> – it works, but PHPStan loses valuable type information.

How to fix it #

Specify the generic type parameters:

 <?php declare(strict_types = 1);
 
 class UserRepository
 {
-	/** @return Collection */
+	/** @return Collection<User> */
 	public function getUsers(): Collection
 	{
 		return new Collection();
 	}
 }

If the collection holds multiple types, specify all required type parameters as defined by the @template tags on the generic class:

<?php declare(strict_types = 1);

/**
 * @template TKey
 * @template TValue
 */
class Map {}

/** @return Map<string, User> */
function getMap(): Map
{
	return new Map();
}

In PHPStan 1.x this error was possible to ignore with configuration parameter checkGenericClassInNonGenericObjectType: false but in PHPStan 2.0 this parameter was removed in favor of ignoring by identifier:

How to ignore this error #

You can use the identifier missingType.generics to ignore this error using a comment:

// @phpstan-ignore missingType.generics
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: missingType.generics

Rules that report this error #

  • PHPStan\Rules\Classes\LocalTypeAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1]
  • PHPStan\Rules\Classes\MethodTagRule [1]
  • PHPStan\Rules\Classes\MethodTagTraitRule [1]
  • PHPStan\Rules\Classes\MethodTagTraitUseRule [1]
  • PHPStan\Rules\Classes\MixinRule [1]
  • PHPStan\Rules\Classes\MixinTraitRule [1]
  • PHPStan\Rules\Classes\MixinTraitUseRule [1]
  • PHPStan\Rules\Classes\PropertyTagRule [1]
  • PHPStan\Rules\Classes\PropertyTagTraitRule [1]
  • PHPStan\Rules\Classes\PropertyTagTraitUseRule [1]
  • PHPStan\Rules\Constants\MissingClassConstantTypehintRule [1]
  • PHPStan\Rules\Functions\MissingFunctionParameterTypehintRule [1]
  • PHPStan\Rules\Functions\MissingFunctionReturnTypehintRule [1]
  • PHPStan\Rules\Generics\ClassAncestorsRule [1]
  • PHPStan\Rules\Generics\EnumAncestorsRule [1]
  • PHPStan\Rules\Generics\InterfaceAncestorsRule [1]
  • PHPStan\Rules\Generics\UsedTraitsRule [1]
  • PHPStan\Rules\Methods\MissingMethodParameterTypehintRule [1]
  • PHPStan\Rules\Methods\MissingMethodReturnTypehintRule [1]
  • PHPStan\Rules\Methods\MissingMethodSelfOutTypeRule [1]
  • PHPStan\Rules\PhpDoc\FunctionAssertRule [1]
  • PHPStan\Rules\PhpDoc\InvalidPhpDocVarTagTypeRule [1]
  • PHPStan\Rules\PhpDoc\MethodAssertRule [1]
  • PHPStan\Rules\Properties\MissingPropertyTypehintRule [1]
  • PHPStan\Rules\Properties\SetPropertyHookParameterRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.