-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Interactivity API: Add typed function to use with generators #65439
base: trunk
Are you sure you want to change the base?
Conversation
…people don’t use it before WP 6.7
This reverts commit ac5590f.
1d4da07
to
d7422d0
Compare
Size Change: +80 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
@sirreal so, what is your proposal for typing asynchronous functions within asynchronous actions? Is there any alternative to the |
I haven't prepared an alternative, the concerns I shared in #64577 (comment) still stand. In particular, I don't like that this introduces new functions into the runtime that are only there to satisfy the type system. I'm not sure the tradeoffs of modifying the runtime and introducing another pattern to what's already a confusing part of the API (use generators with yield instead of async/await) is worth it. It's worth reviewing the issues I linked to see if there are other workarounds. |
I haven't been able to find any other workaround. Using a function seemed to be the only way to change the types without doing a manual casting of the return values: // With `typed`
function* getUser(id: number) {
const user = yield* typed(fetchUser(id));
}
// With manual casting
function* getUser(id: number) {
const user = (yield fetchUser(id)) as Typed<typeof fetchUser>;
} Being |
@luisherranz I really should not be the author of this PR. There's no way to transfer, do you want to create a new PR that can be linked and we can close this one? One thought I had to help this move forward is to make sure it's used and tested in Gutenberg to demonstrate how it improves the experience. The interactivity-router store seems like a good candidate since it's using generators. |
What?
Improve TypeScript support for generators, including converting types to and from promises, and a
typed
function to be able to use promise types when yielding.This PR and branch are to land the
typed
function separately from documentation changes in #64577.Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast