tezvyn:

CodeGen and Typed Scaffolding in the New Architecture

AI-drafted, machine-checkedSource: interviewintermediate
WHAT IT TESTS

CodeGen's purpose.

OUTLINE

it reads typed JS specs and generates native interfaces at build time so JS and native agree on types, avoiding runtime checks and giving compile-time safety.

WHAT THIS TESTS Whether you understand that CodeGen is a build-time tool generating typed interface scaffolding from JS specs, and why that matters.

A GOOD ANSWER COVERS In the New Architecture you define the interface of a TurboModule or Fabric component as a typed JavaScript specification, written in TypeScript or Flow, declaring method signatures, prop types, and events. CodeGen runs at build time, parses these specs, and generates the native scaffolding: the C++ interfaces plus the Java and Objective-C or Objective-C++ binding code that the native implementation conforms to. This matters for two reasons. Type safety: because both the JavaScript usage and the native implementation derive from one shared typed spec, the contract is enforced at compile time, catching mismatched argument or return types during the build rather than as runtime crashes. Performance: with the types known ahead of time, the JSI bindings can pass values directly without the per-call runtime type validation and dynamic conversion the old bridge needed, and there is no hand-written, error-prone glue to maintain. The generated code is the bridge between the typed spec and the actual native logic you write.

COMMON WRONG ANSWERS Thinking CodeGen runs at runtime; it is a build-time step. Believing it generates the actual feature implementation rather than typed interfaces and bindings. Confusing the spec, which you write, with the generated scaffolding, which you do not edit. Ignoring the compile-time type-checking benefit.

LIKELY FOLLOW-UPS Where the spec files live and how they are named. How CodeGen relates to JSI and TurboModules at runtime. What happens when the native implementation does not match the generated interface.

ONE CONCRETE EXAMPLE You write a TurboModule spec in TypeScript declaring getValue taking a string and returning a number. At build time CodeGen produces the C++ and platform interfaces. Your native code implements that generated interface, so a mismatched return type fails the build instead of crashing at runtime, and JSI calls skip per-call type validation.

Read the original → reactnative.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.