-
-
Notifications
You must be signed in to change notification settings - Fork 947
Support refinement of tagged unions of array shapes #6469
Copy link
Copy link
Closed
Labels
Description
Feature request
If we have some types like
@phpstan-type Pizza array{type: 'pizza', toppings: Topping[]}
@phpstan-type Pasta array{type: 'pasta', salsa: Salsa}
@phpstan-type Meal Pizza|Pasta
PHPStan could be able to determine which Meal we have after looking at the type field:
/**
* @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)
}
}
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
Reactions are currently unavailable