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

Commit f659381

Browse files
author
Maxim Shirshin
committed
Generate named type instead of function
1 parent e0934d4 commit f659381

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

src/typings.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ function createExportedClassComponent(m: dom.ModuleDeclaration, componentName: s
112112

113113
function createExportedFunctionalComponent(m: dom.ModuleDeclaration, componentName: string, propTypes: any,
114114
exportType: dom.DeclarationFlags, interf: dom.InterfaceDeclaration): void {
115-
const funcDelc = dom.create.function(componentName, propTypes ? [dom.create.parameter('props', interf)] : [],
116-
dom.create.namedTypeReference('JSX.Element'));
117-
funcDelc.flags = exportType;
118-
m.members.push(funcDelc);
115+
116+
const typeDecl = dom.create.alias(
117+
componentName,
118+
dom.create.namedTypeReference(`React.SFC${ propTypes ? `<${interf.name}>` : '' }`));
119+
typeDecl.flags = exportType;
120+
m.members.push(typeDecl);
119121
}
120122

121123
function createPropTypeTypings(interf: dom.InterfaceDeclaration, ast: AstQuery, propTypes: any,

tests/component-without-proptyes.d.ts renamed to tests/component-without-proptypes.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ declare module 'component' {
88
render(): JSX.Element;
99
}
1010

11-
export function test(): JSX.Element;
11+
export type test = React.SFC;
1212
}
File renamed without changes.

tests/named-export-specifiers.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare module 'component' {
44
optionalAny?: any;
55
}
66

7-
export function Component(props: ComponentProps): JSX.Element;
7+
export type Component = React.SFC<ComponentProps>;
88

9-
export function Component2(): JSX.Element;
9+
export type Component2 = React.SFC;
1010
}

tests/parsing-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('Parsing should create definition from class import PropTypes and instanceO
8585
compare(t, 'component', 'instance-of-proptype-names.jsx', 'instance-of-proptype-names.d.ts');
8686
});
8787
test('Parsing should create definition from file without propTypes', t => {
88-
compare(t, 'component', 'component-without-proptyes.jsx', 'component-without-proptyes.d.ts');
88+
compare(t, 'component', 'component-without-proptypes.jsx', 'component-without-proptypes.d.ts');
8989
});
9090
test('Parsing should create definition from file with references in propTypes', t => {
9191
compare(t, 'component', 'references-in-proptypes.jsx', 'references-in-proptypes.d.ts');

tests/stateless-export-as-default.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ declare module 'component' {
55
className?: string;
66
}
77

8-
export default function Component(props: ComponentProps): JSX.Element;
8+
export default type Component = React.SFC<ComponentProps>;
99
}

tests/stateless.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare module 'component' {
44
optionalAny?: any;
55
}
66

7-
export function Component(props: ComponentProps): JSX.Element;
7+
export type Component = React.SFC<ComponentProps>;
88

9-
export function Component2(): JSX.Element;
9+
export type Component2 = React.SFC;
1010
}

0 commit comments

Comments
 (0)