22
33namespace React \Promise ;
44
5+ /** @psalm-template T */
56interface 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
0 commit comments