Skip to content

Prune no-op Omit keys from generated types#56824

Closed
huntie wants to merge 2 commits into
facebook:mainfrom
huntie:export-D105150070
Closed

Prune no-op Omit keys from generated types#56824
huntie wants to merge 2 commits into
facebook:mainfrom
huntie:export-D105150070

Conversation

@huntie
Copy link
Copy Markdown
Member

@huntie huntie commented May 14, 2026

Summary:
Update the simplifyTypes transform (Flow → TS generation) to prune non-overlapping keys from Omit<> helpers in TypeScript interface unions.

This greatly reduces API snapshot churn/inflation in the next two diffs, which convert a number of type declarations (trivial unions) to interface (Omit<> required for correct union).

In detail

flow-api-translator emits Omit<ParentType, keys> to faithfully translate Flow's object spread override semantics to TypeScript.

// Flow
type Base = {x: string, y: number};
type Child = {...Base, x: boolean}; // Later properties in an object spread override earlier ones

// TypeScript
type Base = {x: string; y: number};
type Child = Omit<Base, "x" | "y"> & {x: boolean};  // Later properties in an object spread *merge*, rather than override. So we must use Omit<> for matched keys.

For interface type unions with overlapping keys, this can result in a number of unnecessary lines in the API snapshot, with little/no human readable value.

This diff extends existing Omit<> handling by simplifyTypes to recursively resolve all property keys reachable from a type, and prune keys that don't exist on the parent type.

// TypeScript
type Child = Omit<Base, "x"> & {x: boolean};  // Only "x" matched - strip `| "y"`
type ChildTwo = Base & {z: string};  // No property collision - strip entire `Omit<>`
  • See changes to ReactNativeApi.d.ts, P2325468482 for examples.
  • Decision point: This diff opts to preserve correctness in TS — even though the snapshot isn't/isn't intended to be read directly/programatically, vs the conciseness tradeoff if we dropped all Omit<>s (human readable but ambiguous to the typechecker).

Changelog: [Internal] - JS API snapshot changes are a simplification refactor only

Differential Revision: D105150070

huntie added 2 commits May 14, 2026 03:51
Summary:

Adds a `--watch` flag to `yarn build-types`. Helpful when debugging output TS types end-to-end.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D104815967
Summary:
Update the `simplifyTypes` transform (Flow → TS generation) to prune/simplify `Omit<>` helpers in TypeScript `interface` unions.

This greatly reduces API snapshot churn in the next two diffs, which convert a number of `type` declarations (trivial unions) to `interface` (`Omit<>` required for correct union).

#### In detail

`flow-api-translator` emits `Omit<ParentType, keys>` to faithfully translate Flow's object spread override semantics to TypeScript.

```
// Flow
type Base = {x: string, y: number};
type Child = {...Base, x: boolean}; // Later properties in an object spread override earlier ones

// TypeScript
type Base = {x: string; y: number};
type Child = Omit<Base, "x"> & {x: boolean};  // Later properties in an object spread *merge*, rather than override. So we must use Omit<> for matched keys.
```

This adds a `collectTypeKeys` utility that recursively resolves all property keys reachable from a type, then uses it as a fallback in the existing `Omit` resolver to prune keys that don't exist on the parent type, or remove the `Omit` entirely when no keys overlap.

- See changes to `ReactNativeApi.d.ts` for examples.
- **Decision point**: This diff opts to preserve correctness in TS — even though the snapshot isn't/isn't intended to be read directly/programatically, vs the conciseness tradeoff if we dropped all `Omit<>`s (human readable but ambiguous to the typechecker).

Changelog: [Internal] - JS API snapshot changes are a simplification refactor only

Differential Revision: D105150070
@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 May 14, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 14, 2026

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

@github-actions
Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

@meta-codesync meta-codesync Bot closed this in 0b9969f May 14, 2026
@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label May 14, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 14, 2026

This pull request has been merged in 0b9969f.

@huntie huntie deleted the export-D105150070 branch May 14, 2026 11:34
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. fb-exported 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