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

feat(generators/readme): add basic support for TS types #1721

Merged
merged 2 commits into from
Dec 31, 2020

Conversation

emmenko
Copy link
Member

@emmenko emmenko commented Dec 30, 2020

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.

@vercel
Copy link

vercel bot commented Dec 30, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/commercetools/ui-kit/6071ii018
✅ Preview: https://ui-kit-git-nm-generator-readme-ts-support.commercetools.vercel.app

@changeset-bot
Copy link

changeset-bot bot commented Dec 30, 2020

⚠️ No Changeset found

Latest commit: b639a0d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +162 to +208
## 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;
}
\`\`\`
Copy link
Member Author

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.

Comment on lines +45 to +48
// @ts-ignore
import * as reactDocgen from 'react-docgen';
// @ts-ignore
import setParamsTypeDefinitionFromFunctionType from 'typescript-react-function-component-props-handler';
Copy link
Member Author

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",
Copy link
Member Author

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

@emmenko emmenko merged commit 58dab57 into master Dec 31, 2020
@emmenko emmenko deleted the nm-generator-readme-ts-support branch December 31, 2020 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant