Skip to content

Fix TS exactOptionalPropertyTypes compatibility for generated types#57628

Open
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D113030161
Open

Fix TS exactOptionalPropertyTypes compatibility for generated types#57628
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D113030161

Conversation

@huntie

@huntie huntie commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary:
NOTE: Patches over a flow-api-translator bug, which I'll fix upstream later. We need to pick this to 0.87-stable to resolve user integration issues.

Context

TypeScript's exactOptionalPropertyTypes flag (strict mode) creates a distinction between foo?: T and foo?: T | undefined.

// Flow's semantics

interface Props {
  onRefresh?: () => void;
}
const a: Props = { onRefresh: undefined }; // ✅ ok
// TypeScript with exactOptionalPropertyTypes: true (i.e. strict mode)

interface Props {
  onRefresh?: () => void;
}
const a: Props = { onRefresh: undefined }; // ❌ error

interface PropsFixed {
  onRefresh?: (() => void) | undefined;
}
const b: PropsFixed = { onRefresh: undefined }; // ✅ ok

With this added strictness in TypeScript, our generated types via flow-api-translator could create downstream type incompatibility in apps.

This diff

Patches the above issue in React Native's Flow → TS types_generated/ pipeline. We transform all instances to the wider foo?: T | undefined format, for maximum compatibility.

Notes

foo?: T [| undefined] remains stripped in the API snapshot (existing transform with the aim of a concise format). There is a net, nonfunctional snapshot diff around function members, which (as a positive result) are re-ordered.

Changelog:
[General][Fixed] - Strict TypeScript API: Optional property types are now widened to explicitly include | undefined for exactOptionalPropertyTypes compatibility

Differential Revision: D113030161

Summary:
NOTE: Patches over a `flow-api-translator` bug, which I'll fix upstream later. We need to pick this to `0.87-stable` to resolve user integration issues.

**Context**

TypeScript's `exactOptionalPropertyTypes` flag (strict mode) creates a distinction between `foo?: T` and `foo?: T | undefined`.

```js
// Flow's semantics

interface Props {
  onRefresh?: () => void;
}
const a: Props = { onRefresh: undefined }; // ✅ ok
```
```ts
// TypeScript with exactOptionalPropertyTypes: true

interface Props {
  onRefresh?: () => void;
}
const a: Props = { onRefresh: undefined }; // ❌ error

interface PropsFixed {
  onRefresh?: (() => void) | undefined;
}
const b: PropsFixed = { onRefresh: undefined }; // ✅ ok
```

With this added strictness in TypeScript, our generated types via `flow-api-translator` could create downstream type incompatibility in apps.

**This diff**

Patches the above issue in React Native's `types_generated/` pipeline. We transform all instances to the wider `| undefined` format, for maximum compatibility.

**Notes**

`| undefined` **remains stripped** in the API snapshot (existing transform with the aim of a concise format). There is a net, nonfunctional snapshot diff around function members, which (as a positive result) are re-ordered.

Changelog:  
[General][Fixed] - **Strict TypeScript API**: Optional property types are now widened to explicitly include `| undefined` for `exactOptionalPropertyTypes` compatibility

Differential Revision: D113030161
@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 Jul 21, 2026
@meta-codesync

meta-codesync Bot commented Jul 21, 2026

Copy link
Copy Markdown

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

@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

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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant