From d60b92dde0db5b8e48dd635454a570b4c605f5f4 Mon Sep 17 00:00:00 2001 From: Pavel Vasek Date: Fri, 8 Sep 2017 20:45:58 +0200 Subject: [PATCH] Props extended from Pick fails - #22 fixed --- package.json | 2 +- src/__tests__/data/ColumnWithPick.tsx | 34 +++++++++++++++++++++++++++ src/__tests__/parser.ts | 12 ++++++++++ src/parser.ts | 5 ++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/data/ColumnWithPick.tsx diff --git a/package.json b/package.json index f6e2784d..4dfc1010 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-docgen-typescript", - "version": "1.0.1", + "version": "1.0.2", "description": "", "main": "lib/index.js", "scripts": { diff --git a/src/__tests__/data/ColumnWithPick.tsx b/src/__tests__/data/ColumnWithPick.tsx new file mode 100644 index 00000000..5d4f893b --- /dev/null +++ b/src/__tests__/data/ColumnWithPick.tsx @@ -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 { + /** propx description */ + propx: number; +} + +/** + * Column description + */ +export class Column extends React.Component { + render() { + const {prop1} = this.props; + return
{prop1}
; + } +} + +export default Column; \ No newline at end of file diff --git a/src/__tests__/parser.ts b/src/__tests__/parser.ts index 3322439f..512e742e 100644 --- a/src/__tests__/parser.ts +++ b/src/__tests__/parser.ts @@ -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: { diff --git a/src/parser.ts b/src/parser.ts index 33497762..87424b79 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -222,6 +222,11 @@ class Parser { */ getFullJsDocComment(symbol: ts.Symbol) { + // in some cases this can be undefined (Pick) + if (symbol.getDocumentationComment === undefined) { + return ""; + } + const mainComment = ts.displayPartsToString(symbol.getDocumentationComment()); const tags = symbol.getJsDocTags() || [];