Bridging JS & C++
Codegen Typings
TypeScript types supported by RNUE Codegen and their generated Unreal C++ types.
@rnue/codegen converts TypeScript types to Unreal C++ types according to the convention below.
This table complements the React Native Codegen typings reference.
Typings map
| TypeScript | Nullable or optional TypeScript | Generated Unreal C++ | Nullable or optional Unreal C++ |
|---|---|---|---|
string | string | null or value?: string | FString | TOptional<FString> |
boolean | boolean | null or value?: boolean | bool | TOptional<bool> |
number | number | null or value?: number | double | TOptional<double> |
CodegenTypes.Double | CodegenTypes.Double | null | double | TOptional<double> |
CodegenTypes.Float | CodegenTypes.Float | null | double | TOptional<double> |
CodegenTypes.Int32 | CodegenTypes.Int32 | null or value?: CodegenTypes.Int32 | int32 | TOptional<int32> |
ReadonlyArray<T> or Array<T> | ReadonlyArray<T> | null or value?: ReadonlyArray<T> | TArray<T> | TOptional<TArray<T>> |
| Object alias or inline object | Nullable or optional object | Generated F struct | TOptional<FRecord> |
Partial<RecordType> | — | Generated F struct with optional fields | Each optional field uses TOptional<T> |
String-literal union, such as "slow" | "fast" | Nullable or optional union | Generated scoped E enum | TOptional<EMode> |
void return | — | void | — |
Notes
CodegenTypes.Int32uses strict conversion. The generated binding rejects fractional, non-finite, and out-of-range values.- Object aliases generate structs in the
<Library>::Generatednamespace. Field names use PascalCase, and Boolean fields use thebprefix. - Nested concrete records are supported. Recursive records are not supported.
- For an applicable schema type,
nullorundefinedproduces an unsetTOptional<T>. - An optional-only parameter accepts omission or
undefined. Addnullto its TypeScript type when the caller can passnull.
Runtime types
Use runtime jsi values only when the schema cannot describe a concrete value.
| TypeScript | Nullable or optional TypeScript | Generated C++ | Notes |
|---|---|---|---|
CodegenTypes.UnsafeObject or dictionary type | Nullable or optional object | facebook::jsi::Object or TOptional<facebook::jsi::Object> | Untyped JavaScript object |
CodegenTypes.UnsafeMixed or unknown | Nullable or optional value | facebook::jsi::Value or TOptional<facebook::jsi::Value> | Dynamic JavaScript value |
| Function or callback | Nullable or optional function | facebook::jsi::Function or TOptional<facebook::jsi::Function> | Runtime-bound callback |
| Array that contains a runtime-bound type | Nullable or optional array | facebook::jsi::Array or TOptional<facebook::jsi::Array> | The complete array remains runtime-bound |
| Non-string union | Nullable or optional union | facebook::jsi::Value or TOptional<facebook::jsi::Value> | Dynamic union value |
TypeScript enum | Nullable or optional enum | facebook::jsi::Value or TOptional<facebook::jsi::Value> | Use a string-literal union for a generated C++ enum |
| Direct tuple | — | Not generated | React Native 0.86 erases tuple element types |
| Array of tuples | Nullable or optional array | facebook::jsi::Array or TOptional<facebook::jsi::Array> | Tuple element types are not available to RNUE Codegen |
Notes
- A method that contains a runtime-bound type receives
facebook::jsi::Runtime& Runtime. - A fully concrete method does not receive a JSI runtime.
- Raw JSI values belong to that runtime and its JavaScript thread. Do not store them or move them to another thread.
- Copy the required data to Unreal-owned values before asynchronous work starts.
- Concrete records and event payloads cannot contain runtime-bound fields. Keep each dynamic value at a method boundary.
- Dictionary types do not generate
TMap. Callback signatures do not generate typed C++ callback wrappers. anyis not a supported schema type. UseCodegenTypes.UnsafeMixedwhen the boundary must accept dynamic data.
Generated method shapes
@rnue/codegen changes TypeScript declarations into generated IService methods and protected event helpers.
| TypeScript declaration | Generated C++ service shape |
|---|---|
setEnabled(enabled: boolean): void | void SetEnabled(bool bEnabled) |
getName(): string | FString GetName() |
getName(): string | null | TOptional<FString> GetName() |
load(): Promise<Result> | void Load(ReactNativeUnreal::TReactPromise<FResult> Promise) |
load(): Promise<Result | null> | void Load(ReactNativeUnreal::TReactPromise<TOptional<FResult>> Promise) |
clear(): Promise<void> | void Clear(ReactNativeUnreal::TReactPromise<void> Promise) |
readonly onReading: CodegenTypes.EventEmitter<Reading> | Protected bool EmitReading(FReading Value) |
Notes
- Typed Promise handles are thread-safe and settle once. They become inert when their React endpoint disconnects.
- Use
Promise.Resolve(Value)orPromise.Resolve()for success. UsePromise.Reject(ReactNativeUnreal::FReactModuleError(...))for an error. - A Promise with a runtime-bound result remains a raw JSI Promise. The service returns
facebook::jsi::Value. - The same method receives
facebook::jsi::Runtime& Runtimeandconst std::shared_ptr<facebook::react::CallInvoker>& JsInvoker. - Event emitters and their payloads are not nullable. Event payloads must use concrete types.
- JavaScript receives an
EventSubscriptionand must callremove()during cleanup.
Naming rules
@rnue/codegen uses the following C++ naming rules:
- TypeScript methods become PascalCase C++ methods.
- Object aliases become structs with an
Fprefix. - String-literal unions become scoped enums with an
Eprefix. - Object fields become PascalCase members.
- Boolean parameters and fields use the
bprefix. - Generated types use the
<Library>::Generatednamespace.