“In legacy React Native, all native modules were eagerly initialized at app launch, bloating startup time. TurboModules load lazily on demand when first accessed. React Native Codegen automatically generates strongly-typed C++ glue code from TypeScript or Flow specifications, guaranteeing compile-time type safety across the language boundary.”
Type-safe native bindings generated automatically from TypeScript specs with lazy on-demand loading.
// NativeStorageSpec.ts (Codegen Specification)
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
export interface Spec extends TurboModule {
getItem(key: string): Promise<string | null>;
setItem(key: string, value: string): Promise<void>;
removeItem(key: string): Promise<void>;
}
export default TurboModuleRegistry.getEnforcing<Spec>('NativeStorage');Developer authors TypeScript module specification: export interface Spec extends TurboModule { ... }
Build step: Codegen parses TS spec and generates C++ header bindings and Java/Obj-C protocols
App startup: TurboModuleRegistry registers module metadata with 0ms initialization overhead
Runtime: JS calls NativeStorage.setItem("token", val)
Engine lazily instantiates C++ HostObject and invokes native OS Keychain/Keystore directly
Lazy module initialization saves 200–500ms of startup latency by loading camera, Bluetooth, and biometrics only when the user opens those screens.