Skip to content

Add LegacyObject to keep Flow Object as Object in the TypeScript API - #59086

Closed
SamChou19815 wants to merge 1 commit into
mainfrom
export-D125245815
Closed

SamChou19815 wants to merge 1 commit into
mainfrom
export-D125245815

Conversation

@SamChou19815

Copy link
Copy Markdown
Member

Summary:
Flow will soon give Object the same meaning as TypeScript's Object, rather than treating it as any. React Native sources that use Object as an untyped escape hatch need to move off it. But the generated TypeScript API (ReactNativeApi.d.ts) relies on Flow Object mapping to TS Object, and it should keep emitting Object.

This adds a LegacyObject global type to bridge the two:

  • Flow: flow/LegacyObject.js declares LegacyObject as any, next to Stringish.
  • TypeScript: build-types replaces LegacyObject with Object before translation, via a new replaceLegacyObjectWithObject pre-transform that mirrors replaceStringishWithString.
  • Codegen: native module specs accept LegacyObject as a generic object, like Object and UnsafeObject.

CodegenTypes.UnsafeObject, the event object types in EventEmitter and NativeEventEmitter, PushNotificationIOS, and the native module specs that used bare Object now use LegacyObject. Neither the generated TypeScript API nor the codegen schema changes. The codegen parser's internal AST aliases (PropAST, ASTNode) switch to plain any.

Changelog: [Internal]

Differential Revision: D125245815

…t API

Summary:
Flow will soon give `Object` the same meaning as TypeScript's `Object`, rather than treating it as `any`. React Native sources that use `Object` as an untyped escape hatch need to move off it. But the generated TypeScript API (`ReactNativeApi.d.ts`) relies on Flow `Object` mapping to TS `Object`, and it should keep emitting `Object`.

This adds a `LegacyObject` global type to bridge the two:
- Flow: `flow/LegacyObject.js` declares `LegacyObject` as `any`, next to `Stringish`.
- TypeScript: build-types replaces `LegacyObject` with `Object` before translation, via a new `replaceLegacyObjectWithObject` pre-transform that mirrors `replaceStringishWithString`.
- Codegen: native module specs accept `LegacyObject` as a generic object, like `Object` and `UnsafeObject`.

`CodegenTypes.UnsafeObject`, the event object types in `EventEmitter` and `NativeEventEmitter`, `PushNotificationIOS`, and the native module specs that used bare `Object` now use `LegacyObject`. Neither the generated TypeScript API nor the codegen schema changes. The codegen parser's internal AST aliases (`PropAST`, `ASTNode`) switch to plain `any`.

Changelog: [Internal]

Differential Revision: D125245815
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown

@SamChou19815 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D125245815.

@meta-codesync meta-codesync Bot closed this in 6671827 Oct 14, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Oct 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown

This pull request has been merged in 6671827.

@SamChou19815
SamChou19815 deleted the export-D125245815 branch October 14, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant