Skip to content

Commit aed4aa9

Browse files
simPodArtem Trushkin
and
Artem Trushkin
committed
Add template annotations
Source: https://github.com/Bocmah/psalm-reactphp-promise-plugin Co-authored-by: Artem Trushkin <[email protected]>
1 parent 29f1ed5 commit aed4aa9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/PromiseInterface.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace React\Promise;
44

5+
/** @psalm-template T */
56
interface PromiseInterface
67
{
78
/**
@@ -28,9 +29,12 @@ interface PromiseInterface
2829
* 2. `$onFulfilled` and `$onRejected` will never be called more
2930
* than once.
3031
*
31-
* @param callable|null $onFulfilled
32-
* @param callable|null $onRejected
33-
* @return PromiseInterface
32+
* @psalm-template TResolved
33+
*
34+
* @psalm-param callable(T):(PromiseInterface<TResolved>|TResolved)|null $onFulfilled
35+
* @psalm-param callable(mixed):(PromiseInterface|mixed)|null $onRejected
36+
*
37+
* @return PromiseInterface<TResolved>
3438
*/
3539
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface;
3640

@@ -44,7 +48,7 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
4448
* Since the purpose of `done()` is consumption rather than transformation,
4549
* `done()` always returns `null`.
4650
*
47-
* @param callable|null $onFulfilled
51+
* @param callable(mixed):TResolve|null $onFulfilled
4852
* @param callable|null $onRejected
4953
* @return void
5054
*/
@@ -60,8 +64,9 @@ public function done(callable $onFulfilled = null, callable $onRejected = null):
6064
* Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
6165
* only specific errors.
6266
*
63-
* @param callable $onRejected
64-
* @return PromiseInterface
67+
* @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
68+
*
69+
* @return PromiseInterface<T>
6570
*/
6671
public function otherwise(callable $onRejected): PromiseInterface;
6772

@@ -108,7 +113,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
108113
* ```
109114
*
110115
* @param callable $onFulfilledOrRejected
111-
* @return PromiseInterface
116+
* @return PromiseInterface<T>
112117
*/
113118
public function always(callable $onFulfilledOrRejected): PromiseInterface;
114119

src/PromisorInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace React\Promise;
44

5+
/** @psalm-template T */
56
interface PromisorInterface
67
{
78
/**
89
* Returns the promise of the deferred.
910
*
10-
* @return PromiseInterface
11+
* @return PromiseInterface<T>
1112
*/
1213
public function promise(): PromiseInterface;
1314
}

0 commit comments

Comments
 (0)