Skip to content

Conversation

hipstersmoothie
Copy link
Contributor

@hipstersmoothie hipstersmoothie commented Sep 4, 2019

In TypeScript 3.0 the way you can specify default props on a component is as follows:

import React from 'react';

interface MyProps {
  foo: string;
}

const MyComponent = (props: MyProps) => {
  // implementation
};

MyComponent.defaultProps = {
  foo: 'bar'
};

export default MyComponent;

Now inside MyComponent the prop foo will be of type string but to the user of the component it will be type string | undefined.

Currently in react-docgen-typescript the above will produce a props table that states foo is required, even though this is not the case.

My changes mark a prop as required only if it not optional and there is a code based default (i.e not a jsdoc default since that code wouldn't type check).

closes #129

@pvasek pvasek merged commit a001036 into styleguidist:master Sep 12, 2019
@pvasek
Copy link
Collaborator

pvasek commented Sep 12, 2019

Thanks! Published on npm as v1.14.1

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.

Typescript 3 Default Props Required Question
2 participants