Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Add shouldRemoveUndefinedFromOptional parser option #98

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ stories.add(
| shouldExtractLiteralValuesFromEnum | boolean | If set to true, string enums and unions will be converted to docgen enum format. Useful if you use Storybook and want to generate knobs automatically using [addon-smart-knobs](https://github.com/storybookjs/addon-smart-knobs). https://github.com/styleguidist/react-docgen-typescript#parseroptions |
| savePropValueAsString | boolean | If set to true, defaultValue to props will be string. https://github.com/styleguidist/react-docgen-typescript#parseroptions |
| typePropName | string | Specify the name of the property for docgen info prop type. |
| shouldRemoveUndefinedFromOptional | boolean | If set to true, types that are optional will not display `| undefined` in the type. https://github.com/styleguidist/react-docgen-typescript#parseroptions |

## Performance

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"@webpack-contrib/schema-utils": "^1.0.0-beta.0",
"loader-utils": "^1.2.3",
"react-docgen-typescript": "^1.15.0"
"react-docgen-typescript": "^1.16.5"
},
"peerDependencies": {
"typescript": "*"
Expand Down
7 changes: 7 additions & 0 deletions src/LoaderOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ export default interface LoaderOptions {
* @default "type"
*/
typePropName?: string;

/**
* If set to true, types that are optional will not display " | undefined" in the type.
*
* @default false
*/
shouldRemoveUndefinedFromOptional?: boolean;
}
2 changes: 2 additions & 0 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function processResource(
shouldExtractLiteralValuesFromEnum:
options.shouldExtractLiteralValuesFromEnum,
savePropValueAsString: options.savePropValueAsString,
shouldRemoveUndefinedFromOptional:
options.shouldRemoveUndefinedFromOptional,
};

// Configure parser using settings provided to loader.
Expand Down
4 changes: 4 additions & 0 deletions src/validateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const schema = {
typePropName: {
type: "string",
},

shouldRemoveUndefinedFromOptional: {
type: "boolean",
},
},
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3979,10 +3979,10 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-docgen-typescript@^1.15.0:
version "1.15.0"
resolved "https://registry.yarnpkg.com/react-docgen-typescript/-/react-docgen-typescript-1.15.0.tgz#963f14210841f9b51ed18c65152a6cc37f1c3184"
integrity sha512-8xObdkRQbrc0505tEdVRO+pdId8pKFyD6jhLYM9FDdceKma+iB+a17Dk7e3lPRBRh8ArQLCedOCOfN/bO338kw==
react-docgen-typescript@^1.16.5:
version "1.16.5"
resolved "https://registry.yarnpkg.com/react-docgen-typescript/-/react-docgen-typescript-1.16.5.tgz#b305563425ab370f5a3c82b42579eb5069449b87"
integrity sha512-guXnx6a554IDVUoVIkX/BGRTrwc2n2w/kMxo7TKLNLJW1qszhT6BRHX4qV8eWq5eaJxRxuesOW5AOLiOI9WQOA==

react-is@^16.8.4:
version "16.9.0"
Expand Down