diff --git a/packages/react-native-codegen/src/parsers/__tests__/parsers-test.js b/packages/react-native-codegen/src/parsers/__tests__/parsers-test.js index 45b9497b1e..92366bc181 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/parsers-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/parsers-test.js @@ -317,6 +317,12 @@ describe('FlowParser', () => { expect(parser.enumDeclaration).toEqual('EnumDeclaration'); }); }); + + describe('interfaceDelcaration', () => { + it('returns interfaceDelcaration Property', () => { + expect(parser.interfaceDelcaration).toEqual('InterfaceDeclaration'); + }); + }); }); describe('TypeScriptParser', () => { @@ -606,4 +612,10 @@ describe('TypeScriptParser', () => { expect(parser.enumDeclaration).toEqual('TSEnumDeclaration'); }); }); + + describe('interfaceDelcaration', () => { + it('returns interfaceDelcaration Property', () => { + expect(parser.interfaceDelcaration).toEqual('TSInterfaceDeclaration'); + }); + }); }); diff --git a/packages/react-native-codegen/src/parsers/flow/parser.js b/packages/react-native-codegen/src/parsers/flow/parser.js index 841c472b3f..1eb2f1d387 100644 --- a/packages/react-native-codegen/src/parsers/flow/parser.js +++ b/packages/react-native-codegen/src/parsers/flow/parser.js @@ -64,6 +64,7 @@ class FlowParser implements Parser { typeParameterInstantiation: string = 'TypeParameterInstantiation'; typeAlias: string = 'TypeAlias'; enumDeclaration: string = 'EnumDeclaration'; + interfaceDelcaration: string = 'InterfaceDeclaration'; isProperty(property: $FlowFixMe): boolean { return property.type === 'ObjectTypeProperty'; diff --git a/packages/react-native-codegen/src/parsers/parser.js b/packages/react-native-codegen/src/parsers/parser.js index c3f83afcae..8ed0526499 100644 --- a/packages/react-native-codegen/src/parsers/parser.js +++ b/packages/react-native-codegen/src/parsers/parser.js @@ -93,6 +93,11 @@ export interface Parser { */ enumDeclaration: string; + /** + * InterfaceDelcaration property of the Parser + */ + interfaceDelcaration: string; + /** * Given a declaration, it returns true if it is a property */ diff --git a/packages/react-native-codegen/src/parsers/parserMock.js b/packages/react-native-codegen/src/parsers/parserMock.js index 65290d70f7..ef3c80d029 100644 --- a/packages/react-native-codegen/src/parsers/parserMock.js +++ b/packages/react-native-codegen/src/parsers/parserMock.js @@ -62,6 +62,7 @@ export class MockedParser implements Parser { typeParameterInstantiation: string = 'TypeParameterInstantiation'; typeAlias: string = 'TypeAlias'; enumDeclaration: string = 'EnumDeclaration'; + interfaceDelcaration: string = 'InterfaceDelcaration'; isProperty(property: $FlowFixMe): boolean { return property.type === 'ObjectTypeProperty'; diff --git a/packages/react-native-codegen/src/parsers/typescript/parser.js b/packages/react-native-codegen/src/parsers/typescript/parser.js index 61c7dc050f..4213cb9212 100644 --- a/packages/react-native-codegen/src/parsers/typescript/parser.js +++ b/packages/react-native-codegen/src/parsers/typescript/parser.js @@ -62,6 +62,7 @@ class TypeScriptParser implements Parser { typeParameterInstantiation: string = 'TSTypeParameterInstantiation'; typeAlias: string = 'TSTypeAliasDeclaration'; enumDeclaration: string = 'TSEnumDeclaration'; + interfaceDelcaration: string = 'TSInterfaceDeclaration'; isProperty(property: $FlowFixMe): boolean { return property.type === 'TSPropertySignature'; diff --git a/packages/react-native-codegen/src/parsers/typescript/utils.js b/packages/react-native-codegen/src/parsers/typescript/utils.js index 1cdf0fe326..e7474f70cb 100644 --- a/packages/react-native-codegen/src/parsers/typescript/utils.js +++ b/packages/react-native-codegen/src/parsers/typescript/utils.js @@ -67,7 +67,7 @@ function resolveTypeAnnotation( node = resolvedTypeAnnotation.typeAnnotation; break; } - case 'TSInterfaceDeclaration': { + case parser.interfaceDelcaration: { typeResolutionStatus = { successful: true, type: 'alias', @@ -87,7 +87,7 @@ function resolveTypeAnnotation( } default: { throw new TypeError( - `A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}'), an interface ('TSInterfaceDeclaration'), or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`, + `A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}'), an interface ('${parser.interfaceDelcaration}'), or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`, ); } }