Skip to content

Commit 5d9c379

Browse files
authored
Merge pull request #46 from pvasek/fix/22_props_from_pick
Props extended from Pick fails - #22 fixed
2 parents 981f3d9 + d60b92d commit 5d9c379

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-docgen-typescript",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "",
55
"main": "lib/index.js",
66
"scripts": {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as React from 'react';
2+
3+
/**
4+
* Column properties.
5+
*/
6+
export interface ManyProps {
7+
/** prop1 description */
8+
prop1?: string;
9+
/** prop2 description */
10+
prop2: number;
11+
/**
12+
* prop3 description
13+
*/
14+
prop3: () => void;
15+
/** prop4 description */
16+
prop4: 'option1' | 'option2' | "option3";
17+
}
18+
19+
export interface ColumnProps extends Pick<ManyProps, 'prop1' | 'prop2'> {
20+
/** propx description */
21+
propx: number;
22+
}
23+
24+
/**
25+
* Column description
26+
*/
27+
export class Column extends React.Component<ColumnProps, {}> {
28+
render() {
29+
const {prop1} = this.props;
30+
return <div>{prop1}</div>;
31+
}
32+
}
33+
34+
export default Column;

src/__tests__/parser.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ describe('parser', () => {
2626
});
2727
});
2828

29+
it('should parse simple react class component with picked properties', function() {
30+
// we are not able to get correct descriptions for prop1,prop2
31+
check('ColumnWithPick', {
32+
Column: {
33+
children,
34+
prop1: { type: 'string', required: false, description: '' },
35+
prop2: { type: 'number', description: '' },
36+
propx: { type: 'number' },
37+
}
38+
});
39+
});
40+
2941
it('should parse HOCs', function() {
3042
check('ColumnHigherOrderComponent', {
3143
ColumnHigherOrderComponent1: {

src/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ class Parser {
222222
*/
223223
getFullJsDocComment(symbol: ts.Symbol) {
224224

225+
// in some cases this can be undefined (Pick<Type, 'prop1'|'prop2'>)
226+
if (symbol.getDocumentationComment === undefined) {
227+
return "";
228+
}
229+
225230
const mainComment = ts.displayPartsToString(symbol.getDocumentationComment());
226231

227232
const tags = symbol.getJsDocTags() || [];

0 commit comments

Comments
 (0)