Repository navigation
Conversation
🦋 Changeset detectedLatest commit: b9e0fb4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
ℹ️ The fix resolves the reported HTML case and compiles cleanly. One coverage note inline.
Reviewed changes
src/types.ts—IntrinsicPropsnow branches on a newIntrinsicElementsHaveDataIndexflag; whenHTMLAttributescarries adata-*template-literal index signature it uses a newWithCSSVarsForDataIndexwidening (intersection, noOmitover the template key) instead ofWithCSSVars, sidestepping the union-complexity limit behind TS2590 (#5796).test-types/template-index-signature.tsx+tsconfig.test-template-index.json— new isolated compile-only type suite augmentingHTMLAttributeswith[dataAttribute:data-${string}]and exercisingstyled.divwith adata-*attribute and a CSS custom property.package.json—test:typesnow also runs the new isolated project..changeset/fuzzy-ravens-smile.md— patch bump with consumer-facing wording.
I verified the fix is load-bearing: reverting IntrinsicProps to the pre-fix WithCSSVars<...> form re-produces TS2590 at styled.tsx(23,33) and src/types.ts, so the new test genuinely fails without the change, and it compiles with the change in place. No acceptance regression observed in the widened style between the two paths.
ℹ️ Nitpicks
- Two parallel widening implementations now coexist (
WithCSSVarsandWithCSSVarsForDataIndex), producing subtly differentstyletypes. They are behaviorally equivalent for intrinsic elements today, but they are separate surfaces to keep in sync; the comments already document the divergence.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| type IntrinsicElementsHaveDataIndex = | ||
| keyof DataAttributes extends keyof React.JSX.IntrinsicElements['div'] ? true : false; |
There was a problem hiding this comment.
The detection probes a single HTML element (div), so the safe widening only activates when the template-literal index lives on HTMLAttributes. An app that augments SVGAttributes with the same data-* pattern still trips TS2590 on styled.svg / styled.path — I confirmed by compiling an SVGAttributes-only augmentation against this branch, which re-produces the exact styled.tsx(23,33) and src/types.ts errors. The reported issue (#5796) is HTML-only, so this is a coverage note rather than a blocker, but the PR title claims general "template index signatures" support.
…ts cost Builds on the data-* template-literal index signature fix. - Widen the augmented intrinsic style through a FastOmit union rather than a plain intersection. A plain intersection forces style to require the custom property index, so an explicit IStyledComponent declaration-site annotation carrying plain CSSProperties no longer relates (a real TS2322). The union form mirrors the normal WithCSSVars widening and keeps that relation intact. - Cover the two cases the reporter flagged that the first patch left untested: the conditional call site (cond ? A : B) and the declaration-site annotation. - Add a --augment mode to typePerf.mjs, with its own budget file and a CI step, so the data-* path's type-check cost (and this regression) is guarded rather than invisible. The default fixture never exercises that path. - Document that the probe detects data-* only; other template prefixes still fall through to the standard widening.
quantizor
left a comment
There was a problem hiding this comment.
Thanks for the fix and the careful reproduction. I pushed a follow-up commit onto the branch: it swaps the augmented-path widening to a FastOmit union so an explicit IStyledComponent declaration-site annotation still relates (a plain intersection forces the custom-property index onto style and breaks that assignment), adds tests for the conditional call site and the annotation, and wires a --augment type-perf budget so the data-* path is guarded in CI. Verified: type tests, both perf budgets, web + native suites all green.
…ponent (#5879) fix(native): prevent TS2590 on Reanimated refs after a styled component The data-* probe added by #5797 uses keyof React.JSX.IntrinsicElements['div']. A React Native app using a styled component will evaluate the probe, and with Reanimated's useAnimatedRef in the code, that will cause TypeScript to show the TS2590 error on the ref (#5877). The probe is now using keyof on each part of the props (ClassAttributes and HTMLAttributes) separately, not on their intersection, which means the same keys are being used. However, checking a DOM tag or web styled.div before the ref will still result in the TS2590 error being shown, as with a normal <div> without styled-components. The new type test will use a data-* index on React.Attributes for checking the ClassAttributes part. This will fail with TS2590 when using the probe on HTMLAttributes only. However, this passes on 6.x as well. In-tree tests cannot fail on 6.x as the trigger requires the React Native and Reanimated types, so #5877 has been added to the out-of-tree list in docs/type-contracts.md. Only the emitted .d.ts files have changed. The built JS is byte for byte identical. These checks passed: test:types, typecheck, prettier:check, test:types:dist, check:type-resolution. type-perf (36,886 types, 738,335 instantiations) and type-perf:augment (37,045 types, 812,680 instantiations) also match 6.x (TypeScript version 5.9.3, @types/react version 18.3.28). test:web and test:native were not run. test:build failed 8/36 on Windows for both base and branch due to the backslashes being removed from the entry path by webpack.

Summary
Fix TypeScript's
TS2590error when applications extend React HTML props with adata-*template-literal index signature. Styled intrinsic elements continue to accept the augmented data attributes and CSS custom properties.Fixes #5796
Testing
pnpm --filter styled-components test:typespnpm buildpnpm --filter styled-components type-perfpnpm testpnpm --filter styled-components prettiergit diff --checkAn AI coding assistant helped investigate the type regression and prepare the patch. I reviewed the resulting diff and verification output.