You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{ state, actions }=store("myPlugin",{actions: {selectItem: (id?: number)=>{constcontext=getContext();// `id` is optional here, so this action can be used in a directive.state.selected=id||context.id;},otherAction: ()=>{// but it can also be called from other actions.actions.selectItem(123);// it works and type is correct}}});
Yes, TypeScript can be used to type stores. There isn’t specific documentation yet, but we are working on a series of new guides for a new section called Core Concepts, and I think we could include one there about TypeScript. I have added it to the tracking issue.
Meanwhile, if you want, you can take a look at this old discussion, which explains some aspects of how the Store of the Interactivity API works, including how it can be typed.
I have opened a pull request to delete the typing:
Description
Actions section of 'Elements of the store' is using TypeScript snippet.
https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/interactivity-api/api-reference.md
Can we use TypeScript snippet without any notice? How do we implement it in
view.js
?Step-by-step reproduction instructions
Refer https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/interactivity-api/api-reference.md
Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
The text was updated successfully, but these errors were encountered: