Menu

← Back to typeAlias.*

Error Identifier: typeAlias.trait

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

trait Timestampable
{
	public \DateTimeInterface $createdAt;
}

/**
 * @phpstan-type EntityType Timestampable
 */
class Config
{
}

Why is it reported? #

A type alias defined via @phpstan-type references a trait, but traits are not valid types in PHP. Traits cannot be used as type declarations, type hints, or in instanceof checks. They are a mechanism for code reuse, not a type in the type system.

How to fix it #

Replace the trait reference with an interface or a class that represents the intended type.

 <?php declare(strict_types = 1);
 
+interface Timestampable
+{
+}
-trait Timestampable
-{
-	public \DateTimeInterface $createdAt;
-}

 /**
  * @phpstan-type EntityType Timestampable
  */
 class Config
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Classes\LocalTypeAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.