[DO-NOT-MERGE] Proof of concept TypeScript theme support with auto-generated human readable js#2614
[DO-NOT-MERGE] Proof of concept TypeScript theme support with auto-generated human readable js#2614SamChou19815 wants to merge 1 commit intofacebook:masterfrom SamChou19815:ts-theme-components-proof-of-concept
Conversation
|
Deploy preview for docusaurus-2 ready! Built with commit ed3b5ac |
| import Layout from '@theme/Layout'; | ||
|
|
||
| function NotFound() { | ||
| function NotFound(): ReactElement { |
There was a problem hiding this comment.
One concern I have is that in the past, I have had a lot of issues with typing react components, because it seems like there are a million different types for components, e.g. React.Component, React.Element, and React.ReactElement (never actually seen this one before). Might this potentially cause type mismatches?
There was a problem hiding this comment.
I just added this to show Babel type stripping works. I don't think we will keep it in final release.
fanny
left a comment
There was a problem hiding this comment.
I wouldn't worry about the return of a render function, since we already know that is a React element or a React node. Although I know that is a POC, I think that we should more concerned about functions types and prop types.
Motivation
This diff shows how I think TypeScript support for themes can be implemented. This is not production ready. This diff only shows how we can generate nice and human-readable js. It doesn't go further to implementing any swizzling logic proposed in #2470.
It uses a simple babel configuration that strip away the typescript types. The generated file's code style is not completely preserved, but it's still very readable. This is what you can get when you run
yarn strip-ts-typesin@docusaurus/theme-classic:(Generated from
src/theme/NotFound.tsx)(You can see from above example that the parentheses around jsx has been stripped away as well. If we really care about the style, we can run
prettieron those generated js file after the babel step.)Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Run
yarn workspace @docusaurus/theme-classic strip-ts-typesto see what's generatedRelated 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.)