Fix TS exactOptionalPropertyTypes compatibility for generated types#57628
Open
huntie wants to merge 1 commit into
Open
Fix TS exactOptionalPropertyTypes compatibility for generated types#57628huntie wants to merge 1 commit into
huntie wants to merge 1 commit into
Conversation
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
|
@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113030161. |
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
NOTE: Patches over a
flow-api-translatorbug, which I'll fix upstream later. We need to pick this to0.87-stableto resolve user integration issues.Context
TypeScript's
exactOptionalPropertyTypesflag (strict mode) creates a distinction betweenfoo?: Tandfoo?: T | undefined.With this added strictness in TypeScript, our generated types via
flow-api-translatorcould 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 widerfoo?: T | undefinedformat, 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
| undefinedforexactOptionalPropertyTypescompatibilityDifferential Revision: D113030161