diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 12fd1194f..bdbe90616 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -414,6 +414,21 @@ class TypeExpander ); } + if ($return_type instanceof Type\Atomic\TObjectWithProperties) { + foreach ($return_type->properties as &$property_type) { + $property_type = self::expandUnion( + $codebase, + $property_type, + $self_class, + $static_class_type, + $parent_class, + $evaluate_class_constants, + $evaluate_conditional_types, + $final + ); + } + } + if ($return_type instanceof Type\Atomic\TCallable || $return_type instanceof Type\Atomic\TFn ) { diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 85d0fad4f..3551674a3 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -315,7 +315,27 @@ class TypeAnnotationTest extends TestCase echo $elt["p1"]; } }' - ] + ], + 'objectWithPropertiesAlias' => [ + '