-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(generators/readme): add basic support for TS types #1721
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/commercetools/ui-kit/6071ii018 |
|
## Signatures | ||
|
||
### Signature identity | ||
|
||
\`\`\`ts | ||
{ | ||
/** | ||
* The name of the Avenger. | ||
*/ | ||
firstName?: string; | ||
lastName?: string; | ||
age?: number; | ||
} | ||
\`\`\` | ||
|
||
### Signature abilities | ||
|
||
\`\`\`ts | ||
{ | ||
/** | ||
* The name of the ability. | ||
*/ | ||
name: string; | ||
description?: string; | ||
/** | ||
* Set this to \`true\` to mark this ability as new. | ||
* | ||
* @@defaultValue@@: false | ||
*/ | ||
isNew?: boolean; | ||
} | ||
\`\`\` | ||
|
||
### Signature movies | ||
|
||
\`\`\`ts | ||
{ | ||
/** | ||
* The title of the movie. | ||
*/ | ||
title: string; | ||
/** | ||
* The release date of the movie (ISO). | ||
*/ | ||
releaseDate: string; | ||
} | ||
\`\`\` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we "embed" the signature types like this, and link to them from the props table.
This way we keep the table simple, while having the type signatures properly documented.
// @ts-ignore | ||
import * as reactDocgen from 'react-docgen'; | ||
// @ts-ignore | ||
import setParamsTypeDefinitionFromFunctionType from 'typescript-react-function-component-props-handler'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be a follow up to provide the "correct" types.
@@ -33,6 +33,7 @@ | |||
"remark-stringify": "9.0.1", | |||
"shelljs": "0.8.4", | |||
"to-vfile": "6.1.0", | |||
"typescript-react-function-component-props-handler": "1.1.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency is used to "fix" an issue with react-docgen
when using FC<>
. See reactjs/react-docgen#387
As we start migrating components to TS, we also need to continue being able to generate the props table.
The
react-docgen
library does support parsing TS types, but the structure is a bit different, so we need to map those use cases separately.This PR adds let's say 80% support for TS types. Special use cases will have to be tackled once we bump into those.