Fix cxx codegen handling of optional return types (#36581)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36581

Found that the current codegen did not properly handle a return type of `?bool` because the branch of `constexpr (is_optional_v<T>)` assumed that T was always a JSI value that needed conversion, and `supportsToJs<bool, bool>` is false.

Changelog: [General][Fixed] Issue with TurboModule C++ codegen with optional return types

Reviewed By: christophpurrer

Differential Revision: D44302352

fbshipit-source-id: 0863de06da4e5e3c18f8a1ced7179d76d8e87b99
This commit is contained in:
Pieter De Baets
2023-03-23 03:10:25 -07:00
committed by Facebook GitHub Bot
parent da027dd2fd
commit dd6d57eea1
5 changed files with 13 additions and 7 deletions
@@ -117,10 +117,10 @@ AsyncPromise<std::string> NativeCxxModuleExample::getValueWithPromise(
return promise;
}
bool NativeCxxModuleExample::getWithWithOptionalArgs(
std::optional<bool> NativeCxxModuleExample::getWithWithOptionalArgs(
jsi::Runtime &rt,
std::optional<bool> optionalArg) {
return optionalArg.value_or(false);
return optionalArg;
}
void NativeCxxModuleExample::voidFunc(jsi::Runtime &rt) {