Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Add template annotations #188

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace React\Promise;

/**
* @psalm-template T
* @psalm-template R
Comment on lines +6 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this can not just use @template?

*/
interface PromiseInterface
{
/**
Expand All @@ -28,9 +32,15 @@ interface PromiseInterface
* 2. `$onFulfilled` and `$onRejected` will never be called more
* than once.
*
* @param callable|null $onFulfilled
* @param callable|null $onRejected
* @return PromiseInterface
* @template TFulfilled of mixed
* @template TRejected of mixed
* @param (callable(T): (PromiseInterface<TFulfilled>|TFulfilled))|null $onFulfilled
* @param (callable(R): (PromiseInterface<TRejected>|TRejected))|null $onRejected
* @return PromiseInterface<(
* $onFulfilled is not null
* ? ($onRejected is not null ? TFulfilled|TRejected : TFulfilled)
* : ($onRejected is not null ? TRejected : R)
* )>
*/
public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface;

Expand All @@ -44,8 +54,9 @@ public function then(?callable $onFulfilled = null, ?callable $onRejected = null
* Additionally, you can type hint the `$reason` argument of `$onRejected` to catch
* only specific errors.
*
* @param callable $onRejected
* @return PromiseInterface
* @param callable(mixed):(PromiseInterface<T>|mixed) $onRejected
*
* @return PromiseInterface<T>
*/
public function catch(callable $onRejected): PromiseInterface;

Expand Down Expand Up @@ -92,7 +103,7 @@ public function catch(callable $onRejected): PromiseInterface;
* ```
*
* @param callable $onFulfilledOrRejected
* @return PromiseInterface
* @return PromiseInterface<T>
*/
public function finally(callable $onFulfilledOrRejected): PromiseInterface;

Expand All @@ -118,7 +129,7 @@ public function cancel(): void;
* ```
*
* @param callable $onRejected
* @return PromiseInterface
* @return PromiseInterface<T>
* @deprecated 3.0.0 Use catch() instead
* @see self::catch()
*/
Expand All @@ -135,7 +146,7 @@ public function otherwise(callable $onRejected): PromiseInterface;
* ```
*
* @param callable $onFulfilledOrRejected
* @return PromiseInterface
* @return PromiseInterface<T>
* @deprecated 3.0.0 Use finally() instead
* @see self::finally()
*/
Expand Down