Error Identifier: typeAlias.importedTemplateType

← Back to typeAlias.*

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 of object
 * @phpstan-type TList list<T>
 */
class Collection
{
}

/**
 * @phpstan-import-type TList from Collection
 */
class Importer
{
}

Why is it reported? #

A type alias defined with @phpstan-type can refer to template types of its class. When such an alias is imported into another class with @phpstan-import-type, the template type has no concrete value there, because the importing class does not know which Collection<...> is meant. The template is replaced with its bound instead. In the example above, TList becomes list<object> in Importer, which is probably not what was intended.

This rule is currently available in bleeding edge.

How to fix it #

Write the type with the concrete type in the importing class instead of importing the alias:

 /**
- * @phpstan-import-type TList from Collection
+ * @phpstan-type TList list<Foo>
  */
 class Importer
 {
 }

Alternatively, make the alias in the source class independent of its template types, so that it means the same thing everywhere it is imported:

 /**
  * @template T of object
- * @phpstan-type TList list<T>
+ * @phpstan-type TList list<object>
  */
 class Collection
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Classes\FunctionTypeAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1]
Theme
© 2026 PHPStan s.r.o.