Skip to content

Commit

Permalink
Props extended from Pick fails - #22 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pvasek committed Sep 8, 2017
1 parent 981f3d9 commit d60b92d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-docgen-typescript",
"version": "1.0.1",
"version": "1.0.2",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/data/ColumnWithPick.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react';

/**
* Column properties.
*/
export interface ManyProps {
/** prop1 description */
prop1?: string;
/** prop2 description */
prop2: number;
/**
* prop3 description
*/
prop3: () => void;
/** prop4 description */
prop4: 'option1' | 'option2' | "option3";
}

export interface ColumnProps extends Pick<ManyProps, 'prop1' | 'prop2'> {
/** propx description */
propx: number;
}

/**
* Column description
*/
export class Column extends React.Component<ColumnProps, {}> {
render() {
const {prop1} = this.props;
return <div>{prop1}</div>;
}
}

export default Column;
12 changes: 12 additions & 0 deletions src/__tests__/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ describe('parser', () => {
});
});

it('should parse simple react class component with picked properties', function() {
// we are not able to get correct descriptions for prop1,prop2
check('ColumnWithPick', {
Column: {
children,
prop1: { type: 'string', required: false, description: '' },
prop2: { type: 'number', description: '' },
propx: { type: 'number' },
}
});
});

it('should parse HOCs', function() {
check('ColumnHigherOrderComponent', {
ColumnHigherOrderComponent1: {
Expand Down
5 changes: 5 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ class Parser {
*/
getFullJsDocComment(symbol: ts.Symbol) {

// in some cases this can be undefined (Pick<Type, 'prop1'|'prop2'>)
if (symbol.getDocumentationComment === undefined) {
return "";
}

const mainComment = ts.displayPartsToString(symbol.getDocumentationComment());

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

0 comments on commit d60b92d

Please sign in to comment.