Skip to content

Commit

Permalink
Add template annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jun 13, 2022
1 parent e63bcec commit 711c097
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace React\Promise;

/**
* @psalm-template T
* @psalm-template R
*/
interface PromiseInterface
{
/**
Expand All @@ -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>|TFulfilled))|null $onFulfilled
* @param (callable(R): (PromiseInterface<TRejected>|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;

Expand All @@ -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<T>|mixed) $onRejected
*
* @return PromiseInterface<T>
*/
public function catch(callable $onRejected): PromiseInterface;

Expand Down Expand Up @@ -92,7 +103,7 @@ public function catch(callable $onRejected): PromiseInterface;
* ```
*
* @param callable $onFulfilledOrRejected
* @return PromiseInterface
* @return PromiseInterface<T>
*/
public function finally(callable $onFulfilledOrRejected): PromiseInterface;

Expand All @@ -118,7 +129,7 @@ public function cancel(): void;
* ```
*
* @param callable $onRejected
* @return PromiseInterface
* @return PromiseInterface<T>
* @deprecated 3.0.0 Use catch() instead
* @see self::catch()
*/
Expand All @@ -135,7 +146,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
* ```
*
* @param callable $onFulfilledOrRejected
* @return PromiseInterface
* @return PromiseInterface<T>
* @deprecated 3.0.0 Use finally() instead
* @see self::finally()
*/
Expand Down

0 comments on commit 711c097

Please sign in to comment.