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 4b7317dac29b7e..b64c48f776a3ee 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 @@ -14,6 +14,7 @@ const { emitBoolean, emitDouble, + emitFloat, emitNumber, emitInt32, emitObject, @@ -424,4 +425,30 @@ describe('emitObject', () => { expect(result).toEqual(expected); }); }); + + describe('emitFloat', () => { + describe('when nullable is true', () => { + it('returns nullable type annotation', () => { + const result = emitFloat(true); + const expected = { + type: 'NullableTypeAnnotation', + typeAnnotation: { + type: 'FloatTypeAnnotation', + }, + }; + + expect(result).toEqual(expected); + }); + }); + describe('when nullable is false', () => { + it('returns non nullable type annotation', () => { + const result = emitFloat(false); + const expected = { + type: 'FloatTypeAnnotation', + }; + + expect(result).toEqual(expected); + }); + }); + }); }); 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 041257f1aacf83..90bbfeda7e3de2 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -43,6 +43,7 @@ const { const { emitBoolean, emitDouble, + emitFloat, emitFunction, emitNumber, emitInt32, @@ -242,9 +243,7 @@ function translateTypeAnnotation( return emitDouble(nullable); } case 'Float': { - return wrapNullable(nullable, { - type: 'FloatTypeAnnotation', - }); + return emitFloat(nullable); } case 'UnsafeObject': case 'Object': { diff --git a/packages/react-native-codegen/src/parsers/parsers-primitives.js b/packages/react-native-codegen/src/parsers/parsers-primitives.js index 6af9551e24abdd..1b450d044ee9b7 100644 --- a/packages/react-native-codegen/src/parsers/parsers-primitives.js +++ b/packages/react-native-codegen/src/parsers/parsers-primitives.js @@ -26,6 +26,7 @@ import type { NativeModulePromiseTypeAnnotation, StringTypeAnnotation, VoidTypeAnnotation, + NativeModuleFloatTypeAnnotation, } from '../CodegenSchema'; import type {ParserType} from './errors'; import type {TypeAliasResolutionStatus} from './utils'; @@ -171,9 +172,18 @@ function emitObject( }); } +function emitFloat( + nullable: boolean, +): Nullable { + return wrapNullable(nullable, { + type: 'FloatTypeAnnotation', + }); +} + module.exports = { emitBoolean, emitDouble, + emitFloat, emitFunction, emitInt32, emitNumber, 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 c66a01ff46927d..5971cc84661026 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 { const { emitBoolean, emitDouble, + emitFloat, emitFunction, emitNumber, emitInt32, @@ -255,9 +256,7 @@ function translateTypeAnnotation( return emitDouble(nullable); } case 'Float': { - return wrapNullable(nullable, { - type: 'FloatTypeAnnotation', - }); + return emitFloat(nullable); } case 'UnsafeObject': case 'Object': {