Skip to content

Commit 76aa69f

Browse files
committed
Add template annotations
1 parent e63bcec commit 76aa69f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/PromiseInterface.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace React\Promise;
44

5+
/** @psalm-template T */
56
interface PromiseInterface
67
{
78
/**
@@ -28,9 +29,11 @@ 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+
* @template TReturn of mixed
33+
*
34+
* @param callable(T): TReturn $callable
35+
*
36+
* @return (TReturn is PromiseInterface ? TReturn : PromiseInterface<TReturn>)
3437
*/
3538
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface;
3639

@@ -44,8 +47,9 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
4447
* Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
4548
* only specific errors.
4649
*
47-
* @param callable $onRejected
48-
* @return PromiseInterface
50+
* @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
51+
*
52+
* @return PromiseInterface<T>
4953
*/
5054
public function catch(callable $onRejected): PromiseInterface;
5155

@@ -92,7 +96,7 @@ public function catch(callable $onRejected): PromiseInterface;
9296
* ```
9397
*
9498
* @param callable $onFulfilledOrRejected
95-
* @return PromiseInterface
99+
* @return PromiseInterface<T>
96100
*/
97101
public function finally(callable $onFulfilledOrRejected): PromiseInterface;
98102

0 commit comments

Comments
 (0)