Skip to content

Commit

Permalink
Merge pull request #46 from pvasek/fix/22_props_from_pick
Browse files Browse the repository at this point in the history
Props extended from Pick fails - #22 fixed
  • Loading branch information
pvasek authored Sep 8, 2017
2 parents 981f3d9 + d60b92d commit 5d9c379
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 5d9c379

Please sign in to comment.