@phpstan-type Pizza array{type: 'pizza', toppings: Topping[]}
@phpstan-type Pasta array{type: 'pasta', salsa: Salsa}
@phpstan-type Meal Pizza|Pasta
/**
* @param Meal $meal
*/
function ($meal) {
if ($meal['type'] === 'pizza') {
\PHPStan\dumpType($meal); // array{type: 'pizza', toppings: Topping[]} (Pizza)
} else {
\PHPStan\dumpType($meal); // array{type: 'pasta', salsa: Salsa} (Pasta)
}
}
Feature request
If we have some types like
PHPStan could be able to determine which Meal we have after looking at the
typefield:https://phpstan.org/r/cacfda2a-94de-4bb6-8da6-2c0d36732967
Flow documentation on disjoint unions: https://flow.org/en/docs/types/unions/#toc-disjointo-object-unions