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

Question/documentation for swizzling components with regards to TypeScript definitions #920

Open
robbieaverill opened this issue Aug 20, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@robbieaverill
Copy link
Contributor

robbieaverill commented Aug 20, 2024

Documentation link

It doesn't exist yet.

Describe the problem

If I swizzle a component, e.g. ApiExplorer/index.tsx, my TypeScript configuration will start complaining with errors such as this:

/ApiExplorer/Response/index.tsx(44,47): error TS2339: Property 'hide_send_button' does not exist on type 'DocFrontMatter'.

As far as I can, this is happening because docusaurus-openapi-docs is extending @docusaurus/theme-common/internal and adding its own custom types to this namespace, and my TypeScript config isn't aware of it.

Is there a recommendation for how to configure tsconfig.json to support these custom types, or plans to stop doing this and define types in this package's namespace instead?

Suggested fix

  • Document how to configure TypeScript to support custom @docusaurus/theme-common/internal type definitions
  • Move custom types into the definitions for this package, remove custom type definitions e.g. theme-classic.d.ts
  • Something else?

Workaround

Swizzling ApiExplorer/index as JavaScript (.tsx) rather than as TypeScript, works as expected.

@ElliotFriend
Copy link
Contributor

v4 of the plugin, released only yesterday, has taken some steps to remove some of the imports from @docusaurus/theme-common/internal. In theory, this "should" make it easier for you to swizzle this component. (Requires docusaurus >= v3.5 I believe.)

I haven't tried the upgrades yet, but I do have a site with a swizzled ApiItem component, too. I'll be able to give it a shot probably next week. If I have anything insightful to share from the experience, provided this hasn't already been resolved, I'll post back here.

@robbieaverill
Copy link
Contributor Author

Thanks for the reply. For what it's worth, many of these errors went away when I removed the classic theme from my dependencies. Perhaps it's a conflict with the classic theme's types against the augmented types that this library adds for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants