From b0bae2124959c5aa8a047769556ef3ebd7615da5 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 7 Feb 2022 08:17:39 -0800 Subject: [PATCH] Improve error when using mutable object as prop Summary: I was trying to add an object property to my ViewManager and got a really opaque error (and I almost thought Objects weren't supported by the codegen) until I realized it expected the object to wrapped in a $ReadOnly type. Changelog: [Internal] Improved error in codegen Reviewed By: mdvacca Differential Revision: D34006557 fbshipit-source-id: b3ab15a40cb66fdcd377f4e68df92060498e8e7f --- .../react-native-codegen/src/parsers/flow/components/props.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/react-native-codegen/src/parsers/flow/components/props.js b/packages/react-native-codegen/src/parsers/flow/components/props.js index 24e08b4493e..1c7982da781 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/props.js +++ b/packages/react-native-codegen/src/parsers/flow/components/props.js @@ -319,6 +319,10 @@ function getTypeAnnotation( `Unsupported union type for "${name}", received "${unionType}"`, ); } + case 'ObjectTypeAnnotation': + throw new Error( + `Cannot use "${type}" type annotation for "${name}": object types must be declared using $ReadOnly<>`, + ); case 'NumberTypeAnnotation': throw new Error( `Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`,