2
2
3
3
namespace React \Promise ;
4
4
5
+ /** @psalm-template T */
5
6
interface PromiseInterface
6
7
{
7
8
/**
@@ -28,9 +29,11 @@ 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
+ * @template TReturn of mixed
33
+ *
34
+ * @param callable(T): TReturn $callable
35
+ *
36
+ * @return (TReturn is PromiseInterface ? TReturn : PromiseInterface<TReturn>)
34
37
*/
35
38
public function then (?callable $ onFulfilled = null , ?callable $ onRejected = null ): PromiseInterface ;
36
39
@@ -44,8 +47,9 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
44
47
* Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
45
48
* only specific errors.
46
49
*
47
- * @param callable $onRejected
48
- * @return PromiseInterface
50
+ * @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
51
+ *
52
+ * @return PromiseInterface<T>
49
53
*/
50
54
public function catch (callable $ onRejected ): PromiseInterface ;
51
55
@@ -92,7 +96,7 @@ public function catch(callable $onRejected): PromiseInterface;
92
96
* ```
93
97
*
94
98
* @param callable $onFulfilledOrRejected
95
- * @return PromiseInterface
99
+ * @return PromiseInterface<T>
96
100
*/
97
101
public function finally (callable $ onFulfilledOrRejected ): PromiseInterface ;
98
102
0 commit comments