Skip to content

Commit 9f2ad4b

Browse files
committed
Add basic template annotations
This adds basic type safety annotations for static analyzers like PHPStan and Psalm. This will cover around 80% of the use cases and a follow-up PR for all supported versions will be proposed later to get it to a 100% of close to a 100%. This PR is a requirement for reactphp/async#40
1 parent 77aa876 commit 9f2ad4b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/PromiseInterface.php

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

33
namespace React\Promise;
44

5+
/** @template T */
56
interface PromiseInterface
67
{
78
/**
@@ -32,10 +33,11 @@ interface PromiseInterface
3233
* than once.
3334
* 3. `$onProgress` (deprecated) may be called multiple times.
3435
*
35-
* @param callable|null $onFulfilled
36+
* @template TReturn of mixed
37+
* @param callable(T): TReturn $onFulfilled
3638
* @param callable|null $onRejected
3739
* @param callable|null $onProgress This argument is deprecated and should not be used anymore.
38-
* @return PromiseInterface
40+
* @return (TReturn is PromiseInterface ? TReturn : PromiseInterface<TReturn>)
3941
*/
4042
public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
4143
}

0 commit comments

Comments
 (0)