22
33namespace React \Promise ;
44
5+ /**
6+ * @psalm-template T
7+ * @psalm-template R
8+ */
59interface PromiseInterface
610{
711 /**
@@ -28,9 +32,15 @@ interface PromiseInterface
2832 * 2. `$onFulfilled` and `$onRejected` will never be called more
2933 * than once.
3034 *
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+ * )>
3444 */
3545 public function then (?callable $ onFulfilled = null , ?callable $ onRejected = null ): PromiseInterface ;
3646
@@ -44,8 +54,9 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
4454 * Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
4555 * only specific errors.
4656 *
47- * @param callable $onRejected
48- * @return PromiseInterface
57+ * @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
58+ *
59+ * @return PromiseInterface<T>
4960 */
5061 public function catch (callable $ onRejected ): PromiseInterface ;
5162
@@ -92,7 +103,7 @@ public function catch(callable $onRejected): PromiseInterface;
92103 * ```
93104 *
94105 * @param callable $onFulfilledOrRejected
95- * @return PromiseInterface
106+ * @return PromiseInterface<T>
96107 */
97108 public function finally (callable $ onFulfilledOrRejected ): PromiseInterface ;
98109
@@ -118,7 +129,7 @@ public function cancel(): void;
118129 * ```
119130 *
120131 * @param callable $onRejected
121- * @return PromiseInterface
132+ * @return PromiseInterface<T>
122133 * @deprecated 3.0.0 Use catch() instead
123134 * @see self::catch()
124135 */
@@ -135,7 +146,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
135146 * ```
136147 *
137148 * @param callable $onFulfilledOrRejected
138- * @return PromiseInterface
149+ * @return PromiseInterface<T>
139150 * @deprecated 3.0.0 Use finally() instead
140151 * @see self::finally()
141152 */
0 commit comments