Skip to main content
InterviewHubPRO
Section Overview
Q47

Question 47 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

94%
React Native & Expo (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

Native Module Authoring with Codegen specs in the New Architecture.

senior LevelCode ExampleSecurity & AuthSystem Design

In Simple Words: In the New Architecture, native modules are strictly type-safe across JavaScript and C++/Swift/Kotlin:

  1. Define the interface in TypeScript using Flow or TypeScript Spec:
    typescript
    // NativeBattery.ts
    import type { TurboModule } from 'react-native';
    import { TurboModuleRegistry } from 'react-native';
    
    export interface Spec extends TurboModule {
      getBatteryLevel(): Promise<number>;
    }
    export default TurboModuleRegistry.getEnforcing<Spec>('NativeBattery');
    
  2. Run Codegen: Generates C++ glue headers enforcing that your native Swift/Kotlin methods match the exact parameter types at compile time.