diff --git a/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js b/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js index c3f73de65da177..cbd850c9f47e21 100644 --- a/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js +++ b/packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js @@ -19,6 +19,7 @@ const { emitObject, emitPromise, emitRootTag, + emitVoid, typeAliasResolution, } = require('../parsers-primitives.js'); @@ -152,6 +153,32 @@ describe('emitDouble', () => { }); }); +describe('emitVoid', () => { + describe('when nullable is true', () => { + it('returns nullable type annotation', () => { + const result = emitVoid(true); + const expected = { + type: 'NullableTypeAnnotation', + typeAnnotation: { + type: 'VoidTypeAnnotation', + }, + }; + + expect(result).toEqual(expected); + }); + }); + describe('when nullable is false', () => { + it('returns non nullable type annotation', () => { + const result = emitVoid(false); + const expected = { + type: 'VoidTypeAnnotation', + }; + + expect(result).toEqual(expected); + }); + }); +}); + describe('typeAliasResolution', () => { const objectTypeAnnotation = { type: 'ObjectTypeAnnotation', diff --git a/packages/react-native-codegen/src/parsers/flow/modules/index.js b/packages/react-native-codegen/src/parsers/flow/modules/index.js index 65b8eef6351490..7a6ccb23f20f03 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -46,6 +46,7 @@ const { emitObject, emitPromise, emitRootTag, + emitVoid, typeAliasResolution, } = require('../../parsers-primitives'); const { @@ -345,9 +346,7 @@ function translateTypeAnnotation( return emitNumber(nullable); } case 'VoidTypeAnnotation': { - return wrapNullable(nullable, { - type: 'VoidTypeAnnotation', - }); + return emitVoid(nullable); } case 'StringTypeAnnotation': { return wrapNullable(nullable, { diff --git a/packages/react-native-codegen/src/parsers/parsers-primitives.js b/packages/react-native-codegen/src/parsers/parsers-primitives.js index 8a0b4fc341d49b..52b47a9a7da1ae 100644 --- a/packages/react-native-codegen/src/parsers/parsers-primitives.js +++ b/packages/react-native-codegen/src/parsers/parsers-primitives.js @@ -23,6 +23,7 @@ import type { ReservedTypeAnnotation, ObjectTypeAnnotation, NativeModulePromiseTypeAnnotation, + VoidTypeAnnotation, } from '../CodegenSchema'; import type {ParserType} from './errors'; import type {TypeAliasResolutionStatus} from './utils'; @@ -65,6 +66,12 @@ function emitDouble(nullable: boolean): Nullable { }); } +function emitVoid(nullable: boolean): Nullable { + return wrapNullable(nullable, { + type: 'VoidTypeAnnotation', + }); +} + function typeAliasResolution( typeAliasResolutionStatus: TypeAliasResolutionStatus, objectTypeAnnotation: ObjectTypeAnnotation< @@ -152,5 +159,6 @@ module.exports = { emitObject, emitPromise, emitRootTag, + emitVoid, typeAliasResolution, }; diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/index.js b/packages/react-native-codegen/src/parsers/typescript/modules/index.js index 9ab51136899e2a..6d1cc95ec7d58e 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/index.js @@ -46,6 +46,7 @@ const { emitObject, emitPromise, emitRootTag, + emitVoid, typeAliasResolution, } = require('../../parsers-primitives'); const { @@ -380,9 +381,7 @@ function translateTypeAnnotation( return emitNumber(nullable); } case 'TSVoidKeyword': { - return wrapNullable(nullable, { - type: 'VoidTypeAnnotation', - }); + return emitVoid(nullable); } case 'TSStringKeyword': { return wrapNullable(nullable, {