Skip to content

TS2590 "union type too complex" in React Native projects using Reanimated since 6.5.3 #5877

Done

Description

@mljlynch

Since 6.5.3, tsc fails with TS2590 in our React Native app, at code that uses a Reanimated animated ref:

src/components/TabBar/TabBar.tsx(158,5): error TS2590: Expression produces a union type that is too complex to represent.

Line 158 is a plain useCallback dependency array, [ref, tabs.length], where ref = useAnimatedRef<Animated.ScrollView>().

Versions: styled-components 6.5.3 and 6.6.0 fail; 6.4.4 through 6.5.2 pass. react-native-reanimated 4.5.1, react-native 0.86.3, React 19.2.3, @types/react 19.2.17 (single copy), TypeScript 5.9.3. We import from styled-components/native, and React.HTMLAttributes is not augmented with a data-* index signature.

What we found

  • The only .d.ts change between 6.5.2 and 6.5.3 is the IntrinsicElementsHaveDataIndex probe and the conditional IntrinsicProps added for TS2590 in styled-components' own .d.ts since 6.5.0 when HTMLAttributes has a template-literal index signature #5796.
  • Editing 6.5.3's types.d.ts so that IntrinsicProps always uses WithCSSVars, or always uses WithCSSVarsForDataIndex, makes the error go away. So does replacing the probe with type IntrinsicElementsHaveDataIndex = false;. Neither props shape fails by itself; evaluating the probe does.
  • A --generateTrace shows the time going into measuring the variance of Reanimated's AnimatedRef (its ExtractElementRef checks TRef extends ElementType and ComponentRef<TRef>).
  • Where the error is reported depends on check order. Working around it in TabBar.tsx moves it to another file's useCallback dependency array that contains a useAnimatedRef<Animated.FlatList<Item>>() ref, with no styled component involved. Adding a file that calls useAnimatedRef<Animated.ScrollView>() early in the program makes the error disappear entirely.

We don't have a standalone repro yet and will add one if we can narrow it down.

Activity

  1. pullfrog commented on Nov 13, 2026

    @pullfrog
  2. mljlynch commented on Nov 13, 2026

    @mljlynch
    Author

    Here's a standalone repro: four files, no app code.

    package.json

    {
      "name": "sc-ts2590-repro",
      "private": true,
      "scripts": { "typecheck": "tsc -p ." },
      "dependencies": {
        "react": "19.2.3",
        "react-native": "0.86.3",
        "react-native-reanimated": "4.5.1",
        "react-native-worklets": "0.10.1",
        "styled-components": "6.5.3"
      },
      "devDependencies": {
        "@types/react": "19.2.17",
        "typescript": "5.9.3"
      }
    }

    tsconfig.json

    {
      "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "lib": ["es2022"],
        "jsx": "react-jsx",
        "noEmit": true,
        "strict": true,
        "moduleResolution": "bundler",
        "customConditions": ["react-native"],
        "skipLibCheck": true
      },
      "include": ["src"]
    }

    src/Text.tsx

    import React from 'react';
    import styled from 'styled-components/native';
    
    const StyledText = styled.Text`
      color: black;
    `;
    
    export const AppText = () => <StyledText />;

    src/useScroll.ts

    import { useCallback } from 'react';
    import Animated, { useAnimatedRef } from 'react-native-reanimated';
    
    export const useScroll = (count: number) => {
      const ref = useAnimatedRef<Animated.ScrollView>();
      return useCallback(() => {
        ref.current?.scrollToEnd();
      }, [ref, count]);
    };
    npm install --ignore-scripts
    npx tsc -p .
    src/useScroll.ts(12,6): error TS2590: Expression produces a union type that is too complex to represent.
    

    Results on this repro:

    Change TS2590
    styled-components 6.5.3 (as above) yes
    styled-components 6.5.2 no
    6.5.3 with type IntrinsicElementsHaveDataIndex = false; in its types.d.ts no
    6.5.3, StyledText defined but never rendered no
    6.5.3, Text.tsx renamed to zText.tsx so it's checked after useScroll.ts no

    So the error needs a native styled component to be rendered somewhere earlier in the program, before AnimatedRef's variance is measured. The two files don't import each other; the failing line is just useScroll.ts's dependency array.

  3. quantizor commented on Nov 25, 2026

    @quantizor
    Contributor

    Released in 6.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions