Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 2f53d2e

Browse files
committed
fix: add react import to SFC typings
1 parent 166d191 commit 2f53d2e

6 files changed

+22
-8
lines changed

Diff for: package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"babel-generator": "^6.26.0",
7070
"babylon": "7.0.0-beta.34",
7171
"chalk": "^2.3.0",
72-
"dts-dom": "^0.1.21",
72+
"dts-dom": "^0.1.24",
7373
"get-stdin": "^5.0.1",
7474
"meow": "^4.0.0",
7575
"pascal-case": "2.0.1",

Diff for: src/typings.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ export function createTypings(moduleName: string|null, programAst: any, options:
4444
...getComponentNamesByStaticPropTypeAttribute(ast),
4545
...getComponentNamesByJsxInBody(ast)
4646
]);
47-
4847
const m = dom.create.module(moduleName || 'moduleName');
49-
if (hasReactClass(ast, reactComponentName)) {
50-
m.members.push(dom.create.importNamed('Component', reactImport));
51-
}
48+
49+
createReactImport(m, ast, reactImport, reactComponentName);
50+
5251
if (importStatements.length > 0) {
5352
importStatements.forEach(importStatement => {
5453
if (importStatement.name === undefined) {
@@ -76,6 +75,15 @@ export function createTypings(moduleName: string|null, programAst: any, options:
7675
}
7776
}
7877

78+
function createReactImport(m: dom.ModuleDeclaration, ast: AstQuery, reactImport: string,
79+
reactComponentName: string|undefined): void {
80+
if (hasReactClass(ast, reactComponentName)) {
81+
m.members.push(dom.create.importNamed('Component', reactImport));
82+
} else {
83+
m.members.push(dom.create.import(reactImport));
84+
}
85+
}
86+
7987
function createExportedTypes(m: dom.ModuleDeclaration, ast: AstQuery, componentName: string,
8088
reactComponentName: string|undefined, propTypes: any, importedPropTypes: ImportedPropTypes,
8189
exportType: dom.DeclarationFlags, options: IOptions): void {

Diff for: tests/named-export-specifiers.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
declare module 'component' {
2+
import 'react';
3+
24
export interface ComponentProps {
35
optionalAny?: any;
46
}

Diff for: tests/stateless-export-as-default.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
declare module 'component' {
2+
import 'react';
3+
24
export interface ComponentProps {
35
text: string;
46
className?: string;

Diff for: tests/stateless.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
declare module 'component' {
2+
import 'react';
3+
24
export interface ComponentProps {
35
optionalAny?: any;
46
}

0 commit comments

Comments
 (0)