TurboModule: typed service API
Prerequisites: 02-jsi-versus-bridge
TurboModule: typed service API — mechanism
Mental model verified
A TurboModule exposes functions and events. A TypeScript or Flow spec describes types, Codegen emits platform glue, and native Android/iOS implementations fulfill that contract. Fabric components handle native views separately.
[S05] [S11]Worked example synthesis
Define getBatteryLevel(): Promise<number> in a typed module spec, implement the platform query separately in Kotlin and Swift/Objective-C++, and handle rejection or missing capability in JS. This is pseudocode for contract shape, not copy-paste setup.
[S05]Engineering choice synthesis
Choose TurboModule when you need RN Codegen contracts or lower-level C++ integration. Keep the exported surface small and versioned; errors and nullability belong in the API design.
[S05] [S06]Pitfall and next step synthesis
Generated types do not make platform behavior identical. Test permission denial, lifecycle and device-specific availability on both platforms.
[S05] [S11]Check yourself: Is a TurboModule the path for custom native visual components?
Use a native component/Fabric view for visual surfaces; a TurboModule exposes nonvisual native functions and events.