2
2
3
3
namespace React \Promise ;
4
4
5
+ /**
6
+ * @psalm-template T
7
+ * @psalm-template R
8
+ */
5
9
interface PromiseInterface
6
10
{
7
11
/**
@@ -28,9 +32,15 @@ interface PromiseInterface
28
32
* 2. `$onFulfilled` and `$onRejected` will never be called more
29
33
* than once.
30
34
*
31
- * @param callable|null $onFulfilled
32
- * @param callable|null $onRejected
33
- * @return PromiseInterface
35
+ * @template TFulfilled of mixed
36
+ * @template TRejected of mixed
37
+ * @param (callable(T): (PromiseInterface<TFulfilled>|TFulfilled))|null $onFulfilled
38
+ * @param (callable(R): (PromiseInterface<TRejected>|TRejected))|null $onRejected
39
+ * @return PromiseInterface<(
40
+ * $onFulfilled is not null
41
+ * ? ($onRejected is not null ? TFulfilled|TRejected : TFulfilled)
42
+ * : ($onRejected is not null ? TRejected : R)
43
+ * )>
34
44
*/
35
45
public function then (?callable $ onFulfilled = null , ?callable $ onRejected = null ): PromiseInterface ;
36
46
@@ -44,8 +54,9 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
44
54
* Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
45
55
* only specific errors.
46
56
*
47
- * @param callable $onRejected
48
- * @return PromiseInterface
57
+ * @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
58
+ *
59
+ * @return PromiseInterface<T>
49
60
*/
50
61
public function catch (callable $ onRejected ): PromiseInterface ;
51
62
@@ -92,7 +103,7 @@ public function catch(callable $onRejected): PromiseInterface;
92
103
* ```
93
104
*
94
105
* @param callable $onFulfilledOrRejected
95
- * @return PromiseInterface
106
+ * @return PromiseInterface<T>
96
107
*/
97
108
public function finally (callable $ onFulfilledOrRejected ): PromiseInterface ;
98
109
@@ -118,7 +129,7 @@ public function cancel(): void;
118
129
* ```
119
130
*
120
131
* @param callable $onRejected
121
- * @return PromiseInterface
132
+ * @return PromiseInterface<T>
122
133
* @deprecated 3.0.0 Use catch() instead
123
134
* @see self::catch()
124
135
*/
@@ -135,7 +146,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
135
146
* ```
136
147
*
137
148
* @param callable $onFulfilledOrRejected
138
- * @return PromiseInterface
149
+ * @return PromiseInterface<T>
139
150
* @deprecated 3.0.0 Use finally() instead
140
151
* @see self::finally()
141
152
*/
0 commit comments