2
2
3
3
namespace React \Promise ;
4
4
5
+ /** @psalm-template T */
5
6
interface PromiseInterface
6
7
{
7
8
/**
@@ -28,9 +29,12 @@ interface PromiseInterface
28
29
* 2. `$onFulfilled` and `$onRejected` will never be called more
29
30
* than once.
30
31
*
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>
34
38
*/
35
39
public function then (?callable $ onFulfilled = null , ?callable $ onRejected = null ): PromiseInterface ;
36
40
@@ -44,7 +48,7 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
44
48
* Since the purpose of `done()` is consumption rather than transformation,
45
49
* `done()` always returns `null`.
46
50
*
47
- * @param callable|null $onFulfilled
51
+ * @param callable(mixed):TResolve |null $onFulfilled
48
52
* @param callable|null $onRejected
49
53
* @return void
50
54
*/
@@ -60,8 +64,9 @@ public function done(callable $onFulfilled = null, callable $onRejected = null):
60
64
* Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
61
65
* only specific errors.
62
66
*
63
- * @param callable $onRejected
64
- * @return PromiseInterface
67
+ * @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
68
+ *
69
+ * @return PromiseInterface<T>
65
70
*/
66
71
public function otherwise (callable $ onRejected ): PromiseInterface ;
67
72
@@ -108,7 +113,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
108
113
* ```
109
114
*
110
115
* @param callable $onFulfilledOrRejected
111
- * @return PromiseInterface
116
+ * @return PromiseInterface<T>
112
117
*/
113
118
public function always (callable $ onFulfilledOrRejected ): PromiseInterface ;
114
119
0 commit comments