diff --git a/src/PromiseInterface.php b/src/PromiseInterface.php index 47117072..486d1473 100644 --- a/src/PromiseInterface.php +++ b/src/PromiseInterface.php @@ -2,6 +2,10 @@ namespace React\Promise; +/** + * @psalm-template T + * @psalm-template R + */ interface PromiseInterface { /** @@ -28,9 +32,15 @@ interface PromiseInterface * 2. `$onFulfilled` and `$onRejected` will never be called more * than once. * - * @param callable|null $onFulfilled - * @param callable|null $onRejected - * @return PromiseInterface + * @template TFulfilled of mixed + * @template TRejected of mixed + * @param (callable(T): (PromiseInterface|TFulfilled))|null $onFulfilled + * @param (callable(R): (PromiseInterface|TRejected))|null $onRejected + * @return PromiseInterface<( + * $onFulfilled is not null + * ? ($onRejected is not null ? TFulfilled|TRejected : TFulfilled) + * : ($onRejected is not null ? TRejected : R) + * )> */ public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface; @@ -44,8 +54,9 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null * Additionally, you can type hint the `$reason` argument of `$onRejected` to catch * only specific errors. * - * @param callable $onRejected - * @return PromiseInterface + * @param callable(mixed):(PromiseInterface|mixed) $onRejected + * + * @return PromiseInterface */ public function catch(callable $onRejected): PromiseInterface; @@ -92,7 +103,7 @@ public function catch(callable $onRejected): PromiseInterface; * ``` * * @param callable $onFulfilledOrRejected - * @return PromiseInterface + * @return PromiseInterface */ public function finally(callable $onFulfilledOrRejected): PromiseInterface; @@ -118,7 +129,7 @@ public function cancel(): void; * ``` * * @param callable $onRejected - * @return PromiseInterface + * @return PromiseInterface * @deprecated 3.0.0 Use catch() instead * @see self::catch() */ @@ -135,7 +146,7 @@ public function otherwise(callable $onRejected): PromiseInterface; * ``` * * @param callable $onFulfilledOrRejected - * @return PromiseInterface + * @return PromiseInterface * @deprecated 3.0.0 Use finally() instead * @see self::finally() */