Files
react-native/scripts/js-api/build-types
Alex Hunt d56683842c Hide runtime-managed class constructors from public API (#57028)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/57028

Mark `ReactNativeElement` and `ReadOnlyNode` as non-user-constructible in the generated TypeScript definitions by emitting `protected constructor()`.

**Motivation**

- Correctness — like web DOM elements (`HTMLElement`, etc.), `ReactNativeElement` instances are created by the React Native runtime, not in user space. See also D107227212.
- Reduce public API surface (in particular, since this is also aliased to the `HostInstance` type).

**Changes**

- Adds a new `build-types protected-constructor` directive and corresponding `build-types` post-transform.
- Applies directive to `ReactNativeElement` and `ReadOnlyNode`.
- Also extracts shared `build-types` directive helpers into `transforms/typescript/utils/buildDirectives.js`.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D107119545

fbshipit-source-id: 8320780db12475b00910745d4b8cee8c9f22d547
2026-06-02 09:19:15 -07:00
..