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

Commit e3d0467

Browse files
committed
fix: remove typeof from instanceOf and symbol prop types
1 parent 7cca176 commit e3d0467

9 files changed

+15
-20
lines changed

Diff for: src/analyzer.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ export function getTypeFromPropType(node: IASTNode, instanceOfResolver = default
8080
break;
8181
case 'instanceOf':
8282
if (type.importPath) {
83-
result.type = 'typeof ' + type.type;
84-
(result as any).importType = type.type;
85-
(result as any).importPath = type.importPath;
83+
result.type = type.type;
84+
result.importPath = type.importPath;
8685
} else {
8786
result.type = 'any';
8887
}

Diff for: src/deprecated.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export enum ExportType {
1313
export interface IProp {
1414
type: string;
1515
optional: boolean;
16-
importType?: string;
1716
importPath?: string;
1817
documentation?: string;
1918
}
@@ -36,8 +35,8 @@ function deprecatedGenerator(generator: Generator, moduleName: string|null,
3635
if (propTypes) {
3736
Object.keys(propTypes).forEach(propName => {
3837
const prop = propTypes[propName];
39-
if (prop.importType && prop.importPath) {
40-
generator.import(prop.importType, prop.importPath);
38+
if (prop.importPath) {
39+
generator.import(prop.type, prop.importPath);
4140
}
4241
});
4342
}

Diff for: src/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function getSimpleType(ast: AstQuery, propertyAst: any,
6969
case 'element':
7070
return getTypeDeclaration(dom.create.namedTypeReference('React.ReactElement<any>'), !required);
7171
case 'symbol':
72-
return getTypeDeclaration(dom.create.typeof(dom.create.namedTypeReference('Symbol')), !required);
72+
return getTypeDeclaration(dom.create.namedTypeReference('Symbol'), !required);
7373
}
7474
return undefined;
7575
}
@@ -79,8 +79,7 @@ function getComplexType(ast: AstQuery, propertyAst: any,
7979
const [required, complexTypeName, typeAst] = getComplexTypeName(ast, propertyAst, importedPropTypes);
8080
switch (complexTypeName) {
8181
case 'instanceOf':
82-
return getTypeDeclaration(dom.create.typeof(
83-
dom.create.namedTypeReference(typeAst.arguments[0].name)), !required);
82+
return getTypeDeclaration(dom.create.namedTypeReference(typeAst.arguments[0].name), !required);
8483
case 'oneOfType':
8584
const typeDecls = typeAst.arguments[0].elements
8685
.map((subtree: any) => get(ast, subtree, importedPropTypes, options)) as TypeDeclaration[];

Diff for: tests/es6-class.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare module 'component' {
3838
optionalString?: string;
3939
optionalNode?: React.ReactNode;
4040
optionalElement?: React.ReactElement<any>;
41-
optionalMessage?: typeof Message;
41+
optionalMessage?: Message;
4242
optionalEnum?: ComponentOptionalEnum;
4343
optionalUnion?: ComponentOptionalUnion;
4444
optionalArrayOf?: number[];
@@ -49,7 +49,7 @@ declare module 'component' {
4949
requiredArrayOf: string[];
5050
requiredArrayOfObjectsWithShape: ComponentRequiredArrayOfObjectsWithShape[];
5151
deeplyNested: ComponentDeeplyNested[];
52-
requiredSymbol: typeof Symbol;
52+
requiredSymbol: Symbol;
5353
}
5454

5555
export class Component extends Component<ComponentProps, any> {

Diff for: tests/es7-class-babeled-to-es6.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare module 'component' {
3838
optionalString?: string;
3939
optionalNode?: React.ReactNode;
4040
optionalElement?: React.ReactElement<any>;
41-
optionalMessage?: typeof Message;
41+
optionalMessage?: Message;
4242
optionalEnum?: MyComponentOptionalEnum;
4343
optionalUnion?: MyComponentOptionalUnion;
4444
optionalArrayOf?: number[];
@@ -49,7 +49,7 @@ declare module 'component' {
4949
requiredArrayOf: string[];
5050
requiredArrayOfObjectsWithShape: MyComponentRequiredArrayOfObjectsWithShape[];
5151
deeplyNested: MyComponentDeeplyNested[];
52-
requiredSymbol: typeof Symbol;
52+
requiredSymbol: Symbol;
5353
}
5454

5555
export class MyComponent extends Component<MyComponentProps, any> {

Diff for: tests/es7-class-top-level-module.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface ComponentProps {
1818
optionalString?: string;
1919
optionalNode?: React.ReactNode;
2020
optionalElement?: React.ReactElement<any>;
21-
optionalMessage?: typeof Message;
21+
optionalMessage?: Message;
2222
optionalUnion?: ComponentOptionalUnion;
2323
optionalArrayOf?: number[];
2424
requiredFunc: (...args: any[]) => any;

Diff for: tests/es7-class.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare module 'component' {
1919
optionalString?: string;
2020
optionalNode?: React.ReactNode;
2121
optionalElement?: React.ReactElement<any>;
22-
optionalMessage?: typeof Message;
22+
optionalMessage?: Message;
2323
optionalUnion?: ComponentOptionalUnion;
2424
optionalArrayOf?: number[];
2525
requiredFunc: (...args: any[]) => any;

Diff for: tests/instance-of-proptype-names.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare module 'component' {
33
import Member from './member';
44

55
export interface TestProps {
6-
test?: typeof Member;
6+
test?: Member;
77
}
88

99
export class Test extends Component<TestProps, any> {

Diff for: tests/parse-prop-types-test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ test('The PropType parser should return number|string for' +
233233
t.is(result.type, 'number|string');
234234
t.is(result.optional, true);
235235
});
236-
test('The PropType parser should return typeof Message for instanceOf(Message) prop types', t => {
236+
test('The PropType parser should return Message for instanceOf(Message) prop types', t => {
237237
const ast: any = {
238238
type: 'CallExpression',
239239
loc: {},
@@ -254,9 +254,8 @@ test('The PropType parser should return typeof Message for instanceOf(Message) p
254254
]
255255
};
256256
const result: IProp = getTypeFromPropType(ast, (): string => './some/path');
257-
t.is(result.type, 'typeof Message');
257+
t.is(result.type, 'Message');
258258
t.is(result.optional, true);
259-
t.is(result.importType, 'Message');
260259
t.is(result.importPath, './some/path');
261260
});
262261
test('The PropType parser should return any for unresolved instanceOf(Message) prop types', t => {
@@ -282,6 +281,5 @@ test('The PropType parser should return any for unresolved instanceOf(Message) p
282281
const result: IProp = getTypeFromPropType(ast);
283282
t.is(result.type, 'any');
284283
t.is(result.optional, true);
285-
t.is(result.importType, undefined);
286284
t.is(result.importPath, undefined);
287285
});

0 commit comments

Comments
 (0)