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

chore(v2): Define type for markdown right table of contents #3306

Merged
merged 1 commit into from
Aug 20, 2020
Merged

chore(v2): Define type for markdown right table of contents #3306

merged 1 commit into from
Aug 20, 2020

Conversation

SamChou19815
Copy link
Contributor

Motivation

Add typing for the rightTOC in @docusaurus/types, so that it can be reference by all plugins and themes.

After this diff, the blog plugin's theme API is fully typed, and we can now correctly type the @theme/TOC component. In a future diff, I plan to use the type for the theme API in docs plugin.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

This PR only adds type annotations, so there should be no runtime change.
To test the accuracy of the type, I added types to @docusaurus/mdx-loader which first produces the TOC. Then I added the type annotation to @theme/TOC component. Both can pass the type checker.

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 19, 2020
Comment on lines +17 to +24
/**
* @typedef {Object} StringValuedNode
* @property {string} type
* @property {string} value
* @property {number} depth
* @property {Object} data
* @property {StringValuedNode[]} children
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the Node type imported from unist doesn't seem to directly usable. The existing code seems to assume that the value field is always string. Therefore, I have to duplicate some type definition here.

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 5dfb1ae

https://deploy-preview-3306--docusaurus-2.netlify.app

@slorber
Copy link
Collaborator

slorber commented Aug 20, 2020

thanks :)

@slorber slorber added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Aug 20, 2020
@slorber slorber merged commit b38f562 into facebook:master Aug 20, 2020
@SamChou19815 SamChou19815 deleted the type-toc branch August 22, 2020 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants