Skip to content

fix(native): avoid TS2590 error on Reanimated refs after a styled component (#5879) - #5889

Merged
quantizor merged 3 commits into
mainfrom
fix/native-probe-ts2590
Nov 24, 2026
Merged

quantizor merged 3 commits into
mainfrom
fix/native-probe-ts2590

Conversation

@quantizor

Copy link
Copy Markdown
Contributor

Forward-ports #5879 to main (v7).

Impact

Apps using styled-components/native alongside Reanimated's useAnimatedRef no longer hit TS2590 ("Expression produces a union type that is too complex to represent") when TypeScript checks a native styled component before the ref. If a DOM element or web styled component is checked earlier in the same program, TypeScript can still report TS2590, as it does for a plain <div> without styled-components.

Changes

  • Narrow IntrinsicElementsHaveDataIndex in packages/styled-components/src/types.ts to probe keyof React.ClassAttributes<HTMLElement> | keyof React.HTMLAttributes<HTMLElement> instead of keyof React.JSX.IntrinsicElements['div'].
  • Add test-types/attributes-index-signature.tsx and tsconfig.test-attributes-index.json (wired into test:types, check:type-resolution, and knip.jsonc) pinning the React.Attributes data-* index augmentation contract.
  • Update docs/typescript-performance.md and add .changeset/native-animated-ref-ts2590.md.

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ab9086d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
styled-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pullfrog pullfrog Bot 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.

ℹ️ Minor suggestions only.

Approach: sound — replacing the JSX.IntrinsicElements['div'] probe with keyed ClassAttributes/HTMLAttributes keeps detection identical for the two documented augmentation sites (their key sets are the same union) while removing the evaluation that exhausted TS's union budget at Reanimated refs.

Reviewed changes

  • Probe narrowing — IntrinsicElementsHaveDataIndex now keys React.ClassAttributes<HTMLElement> | React.HTMLAttributes<HTMLElement>, which is key-for-key equivalent to the old IntrinsicElements['div'] intersection but never expands the intrinsic element map.
  • New regression project — test-types/attributes-index-signature.tsx plus its tsconfig pins the React.Attributes / ClassAttributes half of the probe and mirrors the existing React.HTMLAttributes fixture. I confirmed it fails with TS2590 if that branch is dropped, and passes if the probe reverts to the old expression (matching what the docs state).
  • Wiring and docs — test:types, check:type-resolution, knip.jsonc, docs/typescript-performance.md, and the patch changeset are all updated; the full type gate, check:type-resolution, knip, and Biome pass.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes: the commit since the prior pullfrog review is documentation-only, and it resolves the one prior nit.

  • Fixture rationale documented — the header of attributes-index-signature.tsx now records why its project sets jsx: react-jsx: the React.Attributes augmentation reaches JSX.IntrinsicAttributes, so classic jsx: react fails with TS2322 on fragments in imported src/ files. I re-confirmed this by flipping the tsconfig to jsx: react and reproducing the two errors at StyleSheetManager.tsx:297 and :301; the project passes as committed.

ℹ️ GitHub took this as a comment because it requires explicit repository access to approve or block a pull request here.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@quantizor
quantizor merged commit e7318e3 into main Nov 24, 2026
8 checks passed
@quantizor
quantizor deleted the fix/native-probe-ts2590 branch November 24, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant