diff --git a/package-lock.json b/package-lock.json index 03dfe83..4dc8ac8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-docgen-typescript", - "version": "2.2.3", + "version": "2.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "react-docgen-typescript", - "version": "2.2.3", + "version": "2.3.0", "license": "MIT", "devDependencies": { "@types/chai": "^4.1.0", diff --git a/src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx b/src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx new file mode 100644 index 0000000..ee335fa --- /dev/null +++ b/src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx @@ -0,0 +1,13 @@ +import React from 'react'; + +export interface JumbotronProps { + /** prop1 description */ + prop1: string; +} + +/** + * Jumbotron description + */ +export const Jumbotron: React.FC = props => { + return
Test
; +}; diff --git a/src/__tests__/data/tsconfig.json b/src/__tests__/data/tsconfig.json index 0c90c79..d0b7566 100644 --- a/src/__tests__/data/tsconfig.json +++ b/src/__tests__/data/tsconfig.json @@ -3,6 +3,7 @@ /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "esModuleInterop": true, // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/src/__tests__/parser.ts b/src/__tests__/parser.ts index 16f9cfb..e0db9b8 100644 --- a/src/__tests__/parser.ts +++ b/src/__tests__/parser.ts @@ -776,6 +776,14 @@ describe('parser', () => { }); }); + it('should parse functional component declared as React.FC with default import from react', () => { + check('FunctionalComponentWithDefaultImportReact', { + Jumbotron: { + prop1: { type: 'string', required: true } + } + }); + }); + it('should parse functional component defined as const with default value assignments in immediately destructured props', () => { check('FunctionalComponentWithDesctructuredProps', { FunctionalComponentWithDesctructuredProps: { diff --git a/src/parser.ts b/src/parser.ts index d21f31f..0be4d44 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -113,7 +113,8 @@ export interface FileParser { export const defaultOptions: ts.CompilerOptions = { jsx: ts.JsxEmit.React, module: ts.ModuleKind.CommonJS, - target: ts.ScriptTarget.Latest + target: ts.ScriptTarget.Latest, + esModuleInterop: true }; /**