Files
react-native/scripts/js-api
Alex Hunt cec189bd34 Support 'react-native/react-private-interface' in build-types (#58075)
Summary:
**Motivation**

Minimum infra fix to enable subsequently landing https://github.com/react/react-native/pull/57940.

Referencing `ReactNativeFeatureFlags` on the existing `react-native/react-private-interface` boundary is blocked by a gap in the `build-types` pipeline and a type translation error, addressed here.

**Changes**

- `simpleResolve.js`: Explicitly support `react-native/react-private-interface` as a special case, fixing resolution.
- `ReactNativeFeatureFlagsBase.js`: Tweak the `OverridesFor` type here to fix TypeScript translation compatibility, where the unconstrained `T` type param is now narrowed.

**Impact**

No change to the API snapshot (the `ReactNativeFeatureFlags` import is ultimately tree-shaken!), and no effect on generated types until https://github.com/react/react-native/issues/57940 lands.

Changelog: [Internal]

Pull Request resolved: https://github.com/react/react-native/pull/58075

Test Plan:
- `yarn build-types`
- Applied https://github.com/react/react-native/issues/57940 patch on top; both stayed green, no `types_generated/**/featureflags/**`

Reviewed By: GijsWeterings

Differential Revision: D117513265

Pulled By: cortinico

fbshipit-source-id: 348e8de3d622081fe0062ef939ce14c21af587a8
2026-08-27 05:03:36 -07:00
..

scripts/js-api

TypeScript build pipeline for React Native's JavaScript API.

Overview

yarn build-types is a custom build pipeline for translating React Native's Flow source code to TypeScript.

Specifically, it reduces the runtime JavaScript API of react-native into two outputs:

  • Generated TypeScript types
    Public user types for react-native, shipped to npm
    packages/react-native/types_generated/
  • ‌Public API snapshot
    Snapshot file of the public API shape, used by maintainers
    packages/react-native/ReactNativeApi.d.ts

Dependencies

yarn build-types makes use of the following dependencies, composed with other pre/post transformation steps and dependency resolution.

Usage

Build generated types + API snapshot

Maintainers should run this script whenever making intentional API changes.

# Build types + API snapshot
yarn build-types [--validate]

# Build types without API snapshot
yarn build-types --skip-snapshot

Diff API snapshot compatibility

This script is run by CI to compare changes to ReactNativeApi.d.ts between commits.

# Compare two versions of the API snapshot
yarn js-api-diff <before.d.ts> <after.d.ts>
{
  "result": "BREAKING",
  "changedApis": [
    "ViewStyle"
  ]
}

Configuration

Sparse configuration options are defined and documented in scripts/js-api/config.js.

About the two output formats

Generated TypeScript types

types_generated/

Directory providing TypeScript user types for the react-native package, distributed via npm.

  • Gitignored.
  • Scoped to the index.d.ts entry point via package.json#exports.
  • Preserves unstable_ and experimental_ APIs.
  • Preserves doc comments.
  • Preserves source file names (for go to definition).

Public API snapshot

ReactNativeApi.d.ts

Provides a human-readable, maintainable reference of the React Native's public JavaScript API, optimized for developers and diff tooling.

  • Committed to the repo.
  • Strips unstable_ and experimental_ APIs.
  • Strips doc comments.
  • Strips source file names (types are merged into a single program).
  • Versions exported APIs with an 8 char SHA hash, which will be updated when any input type dependencies change shape.