Menu

← Back to generics.*

Error Identifier: generics.existingTypeAlias

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);

/**
 * @phpstan-type MyAlias string
 * @template MyAlias
 */
class Foo
{
}

Why is it reported? #

A template type parameter has the same name as an existing type alias defined with @phpstan-type or imported with @phpstan-import-type. This creates ambiguity because the name could refer to either the template type or the type alias.

How to fix it #

Rename the template type parameter to avoid the name conflict:

 /**
  * @phpstan-type MyAlias string
- * @template MyAlias
+ * @template T
  */
 class Foo
 {
 }

Or rename the type alias:

 /**
- * @phpstan-type MyAlias string
- * @template MyAlias
+ * @phpstan-type StringAlias string
+ * @template MyAlias
  */
 class Foo
 {
 }

How to ignore this error #

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

// @phpstan-ignore generics.existingTypeAlias
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: generics.existingTypeAlias

Rules that report this error #

  • PHPStan\Rules\Generics\ClassTemplateTypeRule [1]
  • PHPStan\Rules\Generics\FunctionTemplateTypeRule [1]
  • PHPStan\Rules\Generics\InterfaceTemplateTypeRule [1]
  • PHPStan\Rules\Generics\MethodTagTemplateTypeRule [1]
  • PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule [1]
  • PHPStan\Rules\Generics\MethodTemplateTypeRule [1]
  • PHPStan\Rules\Generics\TraitTemplateTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatiblePhpDocTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatiblePropertyHookPhpDocTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatiblePropertyPhpDocTypeRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.