From 9f0d24bb055e4e7d205397cd7052b088c9f06264 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Tue, 12 Aug 2025 23:13:16 -0700 Subject: [PATCH] Enforce void return type for void return type in JS C++ TM spec (#53214) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53214 Changelog: [General] [Fixed] Enforce void return type for void return type in JS C++ TM spec Example if you have this spec ``` export interface Spec extends TurboModule { +foo: (bar: string) => void; } ``` We must enforce in C++ that the return type is `void` as e.g. ``` void foo(jsi::Runtime& rt, const std::string& bar); ``` Right now you can return any type in C++ such as `std::string` which does not make sense Reviewed By: lenaic Differential Revision: D79980538 fbshipit-source-id: 9b99ea6b1ac97d1e46cdb9952e83c445ec5503b7 --- packages/react-native/ReactCommon/react/bridging/Class.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-native/ReactCommon/react/bridging/Class.h b/packages/react-native/ReactCommon/react/bridging/Class.h index 00495a2e140..90a10a00956 100644 --- a/packages/react-native/ReactCommon/react/bridging/Class.h +++ b/packages/react-native/ReactCommon/react/bridging/Class.h @@ -27,6 +27,11 @@ JSReturnT callFromJs( sizeof...(ArgsT) == sizeof...(JSArgsT), "Incorrect arguments length"); static_assert( (supportsFromJs && ...), "Incompatible arguments"); + if constexpr (std::is_void_v) { + static_assert( + std::is_void_v, + "Method must return void when JSReturnT is void"); + } if constexpr (std::is_void_v) { (instance->*method)(