Repository navigation
Description
Since 6.5.0, styled-components' own declaration files fail to type-check with TS2590 when React.HTMLAttributes carries a template-literal index signature — the common augmentation used to allow arbitrary data-* attributes.
Because the errors are located inside node_modules/styled-components/dist/*.d.ts, any project that does not set skipLibCheck: true cannot compile at all.
node_modules/styled-components/dist/constructors/styled.d.ts(13,75): error TS2590: Expression produces a union type that is too complex to represent.
node_modules/styled-components/dist/types.d.ts(169,13): error TS2590: Expression produces a union type that is too complex to represent.
Minimal reproduction
Three files, no styled component ever declared — a bare import is enough, so this is purely declaration-level.
src/react-aug.d.ts
import "react";
declare module "react" {
interface HTMLAttributes<T> {
[dataAttr: `data-${string}`]: string | undefined;
}
}src/index.tsx
import "styled-components";tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx",
"lib": ["DOM", "ES2025"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2025",
"strict": true,
"noEmit": true,
"skipLibCheck": false
},
"include": ["src"]
}npm i [email protected] [email protected] [email protected] \
@types/[email protected] @types/[email protected] @types/[email protected] \
@types/[email protected] [email protected]
npx tsc -p tsconfig.jsonVersions affected
Same repro, only the styled-components version changed:
| version | TS2590 count |
|---|---|
| 6.4.1 | 0 |
| 6.4.2 | 0 |
| 6.4.3 | 0 |
| 6.4.4 | 0 |
| 6.5.0 | 2 |
| 6.5.1 | 2 |
| 6.5.2 | 2 |
Introduced in 6.5.0 and still present in 6.5.2.
Environment: TypeScript 6.0.3, React 19.2.6, @types/react 19.2.17, macOS.
Possible cause
6.5.0 moved the inline-style CSS-custom-property widening into TargetProps, so styled.d.ts:13 now applies it eagerly for every tag:
declare const styled: typeof baseStyled & { [E in SupportedHTMLElements]: StyledInstance<"web", E, TargetProps<"web", E>>; };IntrinsicProps<T> resolves to WithCSSVars<React.JSX.IntrinsicElements[T]>, whose Omit<P, 'style'> is Pick<P, Exclude<keyof P, 'style'>>. When keyof P includes a template-literal key, that Pick appears to be what pushes the union past the complexity limit once it is instantiated across all ~170 elements.
The trigger is specifically a template-literal key, not an index signature in general. Swapping the augmentation to a plain string index signature is fine on every 6.5.x:
augmentation on HTMLAttributes |
6.5.0 | 6.5.1 | 6.5.2 |
|---|---|---|---|
[dataAttr: `data-${string}`]: string | undefined |
2 | 2 | 2 |
[dataAttr: string]: unknown |
0 | 0 | 0 |
(To be clear, the plain-string form was never broken — that row is a contrast, not a regression that 6.5.2 fixed.)
That contrast may still be useful, because the guard added to OverrideStyle in 6.5.2 keys off string exactly:
type OverrideStyle<P extends BaseObject> = P extends unknown ? string extends keyof P ? P : 'style' extends keyof P ? WithCSSVars<P> : P : never;A template-literal key does not satisfy string extends keyof P, so such a prop bag falls through to WithCSSVars. If that guard is the intended escape hatch for index-signature-bearing targets, it may need to recognise template-literal keys too.
Impact and workaround
skipLibCheck: true clears it in a small project, but that is a broad concession for a library-side type error, and it does not fully solve the problem in a real codebase: with skipLibCheck on, the same TS2590 reappears in user code wherever a styled component is picked conditionally, e.g.
// TS2590 at the JSX call site
const Wrapper = props.tiny ? StyledTinyWrapper : StyledWrapper;
return <Wrapper />;Annotating those away (const Wrapper: typeof StyledWrapper = …) works, but has to be repeated per site.
Happy to test a patch against our codebase (a ~3,300-test component library) if that would help.
Activity
pullfrog commentedon Aug 12, 2026
binhpv commentedon Aug 12, 2026
Some follow-up findings, including a correction to what I wrote above about impact.
Which interface is augmented doesn't matter. Any template-literal index signature reachable from element props triggers it, so this isn't specific to
HTMLAttributes:[dataAttr: `data-${string}`])TS2590on 6.5.2HTMLAttributes<T>DOMAttributes<T>AttributesThere is a workaround that doesn't need
skipLibCheck: replace the index signature with the explicitdata-*props actually needed in object position.This is less of a downgrade than it first looks, because TypeScript already allows hyphenated attributes in JSX natively — the index signature only matters for
data-*in object position (.attrs({ "data-role": … }),HTMLProps<…>literals, etc.). In our codebase that was 4 call sites in total, all needing onlydata-role.With that single change, our component library (~3,300 tests, ~170 components) type-checks clean on 6.5.2 with
skipLibCheck: false— no other source changes required.Correction to my "Impact and workaround" section above. I wrote that with
skipLibCheck: truethe sameTS2590reappears in user code at conditionally-selected styled components, and implied that needs per-site annotations as a separate problem. The observation was real, but the diagnosis was wrong: those user-code errors have the same single root cause. Once the augmentation no longer carries a template-literal index signature, they disappear too, and the annotations I had added became unnecessary (I kept them only because they measurably reduce checker memory).So the blast radius is narrower than I first described — one augmentation shape, not a family of separate breakages. Correspondingly, projects hitting this only need to change that augmentation, not adopt
skipLibCheck.The underlying library-side behaviour still looks worth fixing, since a template-literal index signature on
HTMLAttributesis a common pattern for permitting arbitrarydata-*attributes, and 6.4.x handled it fine.binhpv commentedon Aug 12, 2026
@quantizor Feel free to close if you think it's not worth fixing. I just wanted to make sure that it's known as the different when upgrading to 6.5.2
quantizor commentedon Aug 15, 2026
This fix has been released, thanks for reporting!
quantizor commentedon Sep 25, 2026
Closing since the fix shipped in 6.5.3. Thanks again for the detailed bisect and workaround notes.