Looking for help with type safety for react/promise and react/async #7559
Unanswered
WyriHaximus
asked this question in
Q&A
Replies: 1 comment 8 replies
-
I drafted a little something just to show you the basic idea: https://psalm.dev/r/bae938642c I did not get to Observable yet. Can you take a look at it and make me some feedback? I never used Promise so I may have made obvious mistakes here! EDIT: the same but with user code with it to show inference and error detection: https://psalm.dev/r/eb38080b8d |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For
react/promise
andreact/async
(specifically theawait
function in that package) we, the ReactPHP team (@jsor, @cboden, @clue, @SimonFrings, and I) are looking for help making sure our promises are type safe in both Psalm's and PHPStan's eyes.Additionally, I'm looking for the same kind of help with
wyrihaximus/react-awaitable-observable
that builds onreactivex/rxphp
(maintained @davidwdan and @mbonneau). (P.S. I haven't discussed this yet with @davidwdan and @mbonneau for rxphp, but I wanted to know what to propose to that package.) That is very simmular, aside from the fact that it is anitertable
instead of a single value (or exception). But lets start with promises.On
react/promise
this PR reactphp/promise#188 by @simPod was created to add templates for it's type safety. Now we're very happy with that, as this recently came up again while discussingreact/promise
v3 and fibers throughreact/async
'sawait
function. Giving our personal experience with type safety via PHPStan and Psalm we're looking for your help making sure we get the best possible set up for it.To give a few examples, this is what we're aiming to achieve. Let's assume we have this, very basic function that returns a promise that resolves to a string:
Now if we call that function, we're aiming for PHPStorm, Psalm, and PHPStan to understand that this is what we expect:
And this is not what we expect:
Now on top of that, we aim for the
await
function to achieve this:Then there is the
async
function we should also cover as that takes ansync
running bit of code, and runs it in a fiber, and as such will return a promise with the result:This is it with regards to what we're looking for ReactPHP. Personally I'm also looking to achieve the same with observables, with TL;DR are instead of a single value coming from a promise, are stream of values, that just like a promise might take an arbritairy amount of time before the next item in the stream comes in. If observables doesn't ring a bell, reactive or rxjs instead might.
So for Observables I'm looking to achieve exactly the same thing:
How do we achieve this?
Beta Was this translation helpful? Give feedback.
All reactions