Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ export function getTypeFromPropType(node: IASTNode, instanceOfResolver = default
break;
case 'instanceOf':
if (type.importPath) {
result.type = 'typeof ' + type.type;
(result as any).importType = type.type;
(result as any).importPath = type.importPath;
result.type = type.type;
result.importPath = type.importPath;
} else {
result.type = 'any';
}
Expand Down
5 changes: 2 additions & 3 deletions src/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export enum ExportType {
export interface IProp {
type: string;
optional: boolean;
importType?: string;
importPath?: string;
documentation?: string;
}
Expand All @@ -36,8 +35,8 @@ function deprecatedGenerator(generator: Generator, moduleName: string|null,
if (propTypes) {
Object.keys(propTypes).forEach(propName => {
const prop = propTypes[propName];
if (prop.importType && prop.importPath) {
generator.import(prop.importType, prop.importPath);
if (prop.importPath) {
generator.import(prop.type, prop.importPath);
}
});
}
Expand Down
5 changes: 2 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getSimpleType(ast: AstQuery, propertyAst: any,
case 'element':
return getTypeDeclaration(dom.create.namedTypeReference('React.ReactElement<any>'), !required);
case 'symbol':
return getTypeDeclaration(dom.create.typeof(dom.create.namedTypeReference('Symbol')), !required);
return getTypeDeclaration(dom.create.namedTypeReference('Symbol'), !required);
}
return undefined;
}
Expand All @@ -79,8 +79,7 @@ function getComplexType(ast: AstQuery, propertyAst: any,
const [required, complexTypeName, typeAst] = getComplexTypeName(ast, propertyAst, importedPropTypes);
switch (complexTypeName) {
case 'instanceOf':
return getTypeDeclaration(dom.create.typeof(
dom.create.namedTypeReference(typeAst.arguments[0].name)), !required);
return getTypeDeclaration(dom.create.namedTypeReference(typeAst.arguments[0].name), !required);
case 'oneOfType':
const typeDecls = typeAst.arguments[0].elements
.map((subtree: any) => get(ast, subtree, importedPropTypes, options)) as TypeDeclaration[];
Expand Down
4 changes: 2 additions & 2 deletions tests/es6-class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare module 'component' {
optionalString?: string;
optionalNode?: React.ReactNode;
optionalElement?: React.ReactElement<any>;
optionalMessage?: typeof Message;
optionalMessage?: Message;
optionalEnum?: ComponentOptionalEnum;
optionalUnion?: ComponentOptionalUnion;
optionalArrayOf?: number[];
Expand All @@ -49,7 +49,7 @@ declare module 'component' {
requiredArrayOf: string[];
requiredArrayOfObjectsWithShape: ComponentRequiredArrayOfObjectsWithShape[];
deeplyNested: ComponentDeeplyNested[];
requiredSymbol: typeof Symbol;
requiredSymbol: Symbol;
}

export class Component extends Component<ComponentProps, any> {
Expand Down
4 changes: 2 additions & 2 deletions tests/es7-class-babeled-to-es6.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare module 'component' {
optionalString?: string;
optionalNode?: React.ReactNode;
optionalElement?: React.ReactElement<any>;
optionalMessage?: typeof Message;
optionalMessage?: Message;
optionalEnum?: MyComponentOptionalEnum;
optionalUnion?: MyComponentOptionalUnion;
optionalArrayOf?: number[];
Expand All @@ -49,7 +49,7 @@ declare module 'component' {
requiredArrayOf: string[];
requiredArrayOfObjectsWithShape: MyComponentRequiredArrayOfObjectsWithShape[];
deeplyNested: MyComponentDeeplyNested[];
requiredSymbol: typeof Symbol;
requiredSymbol: Symbol;
}

export class MyComponent extends Component<MyComponentProps, any> {
Expand Down
2 changes: 1 addition & 1 deletion tests/es7-class-top-level-module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface ComponentProps {
optionalString?: string;
optionalNode?: React.ReactNode;
optionalElement?: React.ReactElement<any>;
optionalMessage?: typeof Message;
optionalMessage?: Message;
optionalUnion?: ComponentOptionalUnion;
optionalArrayOf?: number[];
requiredFunc: (...args: any[]) => any;
Expand Down
2 changes: 1 addition & 1 deletion tests/es7-class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare module 'component' {
optionalString?: string;
optionalNode?: React.ReactNode;
optionalElement?: React.ReactElement<any>;
optionalMessage?: typeof Message;
optionalMessage?: Message;
optionalUnion?: ComponentOptionalUnion;
optionalArrayOf?: number[];
requiredFunc: (...args: any[]) => any;
Expand Down
2 changes: 1 addition & 1 deletion tests/instance-of-proptype-names.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module 'component' {
import Member from './member';

export interface TestProps {
test?: typeof Member;
test?: Member;
}

export class Test extends Component<TestProps, any> {
Expand Down
6 changes: 2 additions & 4 deletions tests/parse-prop-types-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ test('The PropType parser should return number|string for' +
t.is(result.type, 'number|string');
t.is(result.optional, true);
});
test('The PropType parser should return typeof Message for instanceOf(Message) prop types', t => {
test('The PropType parser should return Message for instanceOf(Message) prop types', t => {
const ast: any = {
type: 'CallExpression',
loc: {},
Expand All @@ -254,9 +254,8 @@ test('The PropType parser should return typeof Message for instanceOf(Message) p
]
};
const result: IProp = getTypeFromPropType(ast, (): string => './some/path');
t.is(result.type, 'typeof Message');
t.is(result.type, 'Message');
t.is(result.optional, true);
t.is(result.importType, 'Message');
t.is(result.importPath, './some/path');
});
test('The PropType parser should return any for unresolved instanceOf(Message) prop types', t => {
Expand All @@ -282,6 +281,5 @@ test('The PropType parser should return any for unresolved instanceOf(Message) p
const result: IProp = getTypeFromPropType(ast);
t.is(result.type, 'any');
t.is(result.optional, true);
t.is(result.importType, undefined);
t.is(result.importPath, undefined);
});