[3.x] Add template annotations#247
Conversation
c6131bf to
e48bb63
Compare
clue
left a comment
There was a problem hiding this comment.
@WyriHaximus Solid progress! 👍
For context: We've had a call together with @WyriHaximus and @SimonFrings earlier today, discussing our progress for template annotations and unhandled rejections. We've discussed most of these points internally already, but figured it makes sense to post here as well for transparency.
6772ffb to
bb7d812
Compare
Adds template annotations turning the `PromiseInterface` into a generic.
Variables `$p1` and `$p2` in the following code example both are
`PromiseInterface<int|string>`.
```php
$f = function (): int|string {
return time() % 2 ? 'string' : time();
};
/**
* @return PromiseInterface<int|string>
*/
$fp = function (): PromiseInterface {
return resolve(time() % 2 ? 'string' : time());
};
$p1 = resolve($f());
$p2 = $fp();
```
When calling `then` on `$p1` or `$p2`, PHPStan understand that function
`$f1` is type hinting its parameter fine, but `$f2` will throw during
runtime:
```php
$p2->then(static function (int|string $a) {});
$p2->then(static function (bool $a) {});
```
Builds on top of reactphp#246 and
reactphp#188 and is a requirement for
reactphp/async#40
clue
left a comment
There was a problem hiding this comment.
@WyriHaximus Went over your changes together with @SimonFrings and addressed all outstanding issues, great work, now let's get this shipped!
![]()
|
@clue @SimonFrings Thank you for picking up and finishing this off and having my back in these challenging personal times ❤️ . |
|
@WyriHaximus No problem, we're here! Happy to support you during tough times. Take care and stay strong! |
Adds template annotations turning the
PromiseInterfaceinto a generic.Variables
$p1and$p2in the following code example both arePromiseInterface<int|string>.When calling
thenon$p1or$p2, PHPStan understand that function$f1is type hinting its parameter fine, but$f2will throw during runtime:Builds on top of #246 and #188 and is a requirement for reactphp/async#40