Skip to content

Fix strict transform array element type - #57908

Open
Boulea7 wants to merge 3 commits into
react:mainfrom
Boulea7:fix/react-native-strict-api-transform
Open

Boulea7 wants to merge 3 commits into
react:mainfrom
Boulea7:fix/react-native-strict-api-transform

Conversation

@Boulea7

@Boulea7 Boulea7 commented Aug 12, 2026 •

Copy link
Copy Markdown

Summary:

Fixes #53899.

MergeUnion made every transform key optional before MaximumOneOf selected a key. Indexing that optional mapped type added undefined to each element of ViewStyle['transform'] under strict null checks. This makes the intermediate keys required, preserving the existing one-key transform constraint while keeping undefined out of the array element type.

Changelog:

[General] [Fixed] - Prevent strict transform array element types from including undefined

Test Plan:

Validated against main at d7ff82ebe4ed5155b955fd60b31e02bbc76a3c66:

  • yarn build-types and yarn build-types --validate — passed; the snapshot was regenerated from Flow and is up to date.
  • yarn test-generated-typescript and yarn test-typescript-legacy — passed.
  • yarn test scripts/js-api/build-types --runInBand --ci --no-cache — 21 suites, 149 tests, and 131 snapshots passed.
  • rn_flow_tmp=$(mktemp -d) && yarn flow-check --max-workers 8 --temp-dir "$rn_flow_tmp" — passed; this is a copyable equivalent of the isolated temporary-directory invocation used for validation.
  • ./node_modules/.bin/prettier --check packages/react-native/Libraries/StyleSheet/private/_TransformStyle.js packages/react-native/ReactNativeApi.d.ts — passed.
  • ./node_modules/.bin/eslint --max-warnings 0 packages/react-native/Libraries/StyleSheet/private/_TransformStyle.js — passed.
  • git diff --check d7ff82ebe4ed5155b955fd60b31e02bbc76a3c66 -- — passed.

The generated and legacy TypeScript suites use strict: false, so they do not exercise this strict-null regression. After generating types, the following standalone command reproduces the public-type check from the repository root. It creates a temporary probe inside the checkout so react-native resolves to the generated workspace types, then removes only that file and its directory even when the check fails:

(
  set -e
  rn_probe_dir=$(mktemp -d ./.rn-transform-probe.XXXXXX)
  trap 'rm -f -- "$rn_probe_dir/transform-probe.ts"; rmdir -- "$rn_probe_dir"' EXIT
  cat > "$rn_probe_dir/transform-probe.ts" <<'TS'
import type {ViewStyle} from 'react-native';

function transformKeys(transform: NonNullable<ViewStyle['transform']>) {
  if (typeof transform === 'string') {
    return [];
  }
  return transform.map(element => Object.keys(element));
}

void transformKeys;
TS
  ./node_modules/.bin/tsc --noEmit --strictNullChecks --skipLibCheck --moduleResolution bundler --module esnext --target es2020 --jsx react --types react "$rn_probe_dir/transform-probe.ts"
)

On unmodified main, this probe fails with TS2769 at Object.keys(element) because the array element includes undefined. The same probe passes after the fix and regeneration. Additional temporary checks passed for single-key objects, readonly arrays, animated values, string transforms, an omitted transform, and the existing optional selected property; they also confirm rejection of undefined array elements and objects with multiple transform keys. Those boundary checks are not part of the minimal command above.

No additional test script or strict TypeScript configuration is included in this PR, as requested in review.

The full repository lint and Jest suites, native builds, and RNTester were not run for this type-only change.

Codex was used for this update and its validation.

@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 Aug 12, 2026
@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

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 12, 2026
Comment thread package.json Outdated
@Boulea7
Boulea7 force-pushed the fix/react-native-strict-api-transform branch from 848cb39 to 6c27484 Compare August 12, 2026 18:37
@Boulea7
Boulea7 force-pushed the fix/react-native-strict-api-transform branch from 6c27484 to 66b3f45 Compare August 12, 2026 18:41
Copilot AI lite review requested due to automatic review settings September 26, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TypeScript] react-native-strict-api transform can be undefined

3 participants