Addon-docs: Remove undefined from optional values in Typescript Props

This commit is contained in:
Michael Shilman 2020-07-11 09:05:02 +08:00
parent 8ab8425ec5
commit 7b922e4e0a
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import React from 'react';
// Repro #11019
interface Props {
kind?: 'a' | 'b';
disabled?: boolean;
}
export const OptionalButton = ({ disabled = false, kind = 'a' }: Props) => (
// eslint-disable-next-line react/button-has-type
<button {...{ disabled }}>Repro</button>
);
export default OptionalButton;

View File

@ -4,6 +4,7 @@ import { DocgenButton } from '../../components/DocgenButton';
import { ButtonGroup, SubGroup } from '../../components/ButtonGroup';
import { ForwardRefButton } from '../../components/ForwardRefButton';
import { MemoButton } from '../../components/MemoButton';
import { OptionalButton } from '../../components/OptionalButton';
<Meta
title="Addons/Docs/props"
@ -160,3 +161,7 @@ export const Template = (args = {}) => (
## Component
<Props of={DocgenButton} />
## OptionalButton
<Props of={OptionalButton} />

View File

@ -3,6 +3,7 @@ export const typeScriptDefaults = {
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
},
};