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

Docs: Interactivity API - TypeScript snippet is used in the sample. #64418

Closed
2 tasks done
atachibana opened this issue Aug 10, 2024 · 1 comment · Fixed by #64429
Closed
2 tasks done

Docs: Interactivity API - TypeScript snippet is used in the sample. #64418

atachibana opened this issue Aug 10, 2024 · 1 comment · Fixed by #64429
Labels
[Type] Bug An existing feature does not function as intended

Comments

@atachibana
Copy link
Contributor

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?

const { state, actions } = store("myPlugin", {
  actions: {
    selectItem: (id?: number) => {
      const context = 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
    }
  }
});

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.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes
@atachibana atachibana added the [Type] Bug An existing feature does not function as intended label Aug 10, 2024
@luisherranz luisherranz linked a pull request Aug 12, 2024 that will close this issue
@luisherranz
Copy link
Member

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants