Skip to content

Commit

Permalink
Add template annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod and Artem Trushkin committed Mar 15, 2021
1 parent 29f1ed5 commit aed4aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace React\Promise;

/** @psalm-template T */
interface PromiseInterface
{
/**
Expand All @@ -28,9 +29,12 @@ interface PromiseInterface
* 2. `$onFulfilled` and `$onRejected` will never be called more
* than once.
*
* @param callable|null $onFulfilled
* @param callable|null $onRejected
* @return PromiseInterface
* @psalm-template TResolved
*
* @psalm-param callable(T):(PromiseInterface<TResolved>|TResolved)|null $onFulfilled
* @psalm-param callable(mixed):(PromiseInterface|mixed)|null $onRejected
*
* @return PromiseInterface<TResolved>
*/
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface;

Expand All @@ -44,7 +48,7 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
* Since the purpose of `done()` is consumption rather than transformation,
* `done()` always returns `null`.
*
* @param callable|null $onFulfilled
* @param callable(mixed):TResolve|null $onFulfilled
* @param callable|null $onRejected
* @return void
*/
Expand All @@ -60,8 +64,9 @@ public function done(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 otherwise(callable $onRejected): PromiseInterface;

Expand Down Expand Up @@ -108,7 +113,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
* ```
*
* @param callable $onFulfilledOrRejected
* @return PromiseInterface
* @return PromiseInterface<T>
*/
public function always(callable $onFulfilledOrRejected): PromiseInterface;

Expand Down
3 changes: 2 additions & 1 deletion src/PromisorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace React\Promise;

/** @psalm-template T */
interface PromisorInterface
{
/**
* Returns the promise of the deferred.
*
* @return PromiseInterface
* @return PromiseInterface<T>
*/
public function promise(): PromiseInterface;
}

0 comments on commit aed4aa9

Please sign in to comment.