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

Inferring type from constrained generics #318

Merged
merged 1 commit into from
Jan 2, 2021

Conversation

Muritavo
Copy link
Contributor

The following pull request modifies how generics are handled by the docgen typing generation, for better support for generic enums when used with storybook.

Consider the following case:

function Component<T extends string>(props: { aGenericProp: T }) { return null }

The current implementation makes the generated type to be T that storybook resolves to any.
With this change it's checked if the typing is constrained, and if so, obtains the typing from the constraint.

So when it resolves it will see the component definition as:

function Component<T extends string>(props: { aGenericProp: string }) { return null }

These are the changes that have been made:

  • GenericWithExtends.tsx: Exemplifies a use case and is used by the tests
  • tests/parser.ts: This changes affects others tests that had the same structure, so some tests assertions were modified
  • src/parser.ts: When generation the documentation, if the type has some constraint, generate the docs from the constraint

@Muritavo Muritavo closed this Dec 28, 2020
@Muritavo Muritavo reopened this Dec 28, 2020
@pvasek pvasek merged commit ab12fad into styleguidist:master Jan 2, 2021
@Muritavo Muritavo deleted the feature/type_from_generics branch January 2, 2021 19:13
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.

2 participants