Menu

← Back to typeAlias.*

Error Identifier: typeAlias.duplicate

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

class SomeClass
{
}

/**
 * @phpstan-import-type SomeClass from AnotherClass
 */
class Foo
{
}

Why is it reported? #

A type alias imported via @phpstan-import-type or defined via @phpstan-type conflicts with an existing class, interface, trait, or enum name in the current scope. In the example above, importing a type alias named SomeClass conflicts with the existing SomeClass class.

This ambiguity would make it unclear whether SomeClass refers to the actual class or the type alias.

How to fix it #

Use the as keyword to rename the imported type alias to avoid the conflict:

 <?php declare(strict_types = 1);
 
 /**
- * @phpstan-import-type SomeClass from AnotherClass
+ * @phpstan-import-type SomeClass from AnotherClass as SomeClassAlias
  */
 class Foo
 {
 }

Or choose a different name for the local type alias:

 <?php declare(strict_types = 1);
 
 /**
- * @phpstan-type MyAlias string
+ * @phpstan-type MyStringAlias string
  */
 class Foo
 {
 }

How to ignore this error #

You can use the identifier typeAlias.duplicate to ignore this error using a comment:

// @phpstan-ignore typeAlias.duplicate
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: typeAlias.duplicate

Rules that report this error #

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.