Skip to content

fix(headless): correct transform type inference in useAnimatedStyle hooks - #43

Open
truongnat wants to merge 3 commits into
developfrom
fix/use-slider-type-error-6122752136857926757
Open

fix(headless): correct transform type inference in useAnimatedStyle hooks#43
truongnat wants to merge 3 commits into
developfrom
fix/use-slider-type-error-6122752136857926757

Conversation

@truongnat

@truongnat truongnat commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Fixed type errors where useAnimatedStyle could not correctly infer the return type for its transform property arrays (e.g., complaining that translateY and scale objects do not match DefaultStyle). Casted the return statements strictly to import('react-native').ViewStyle. Removed temporary debug files and ensured the headless package continues to typecheck cleanly.


PR created automatically by Jules for task 6122752136857926757 started by @truongnat


🔧 This PR fixes TypeScript compilation errors in React Native Reanimated's useAnimatedStyle hooks by explicitly typing return values as ViewStyle and casting scale transforms to resolve type inference issues.

🔍 Detailed Analysis

Key Changes

  • Type Annotations: Added explicit import('react-native').ViewStyle return type annotations to useAnimatedStyle callbacks in both useScrollHeader.ts and useSlider.ts
  • Transform Casting: Applied as never casting to scale transform properties to resolve TypeScript's union type inference conflicts
  • Error Resolution: Fixed TS2345 compiler errors where Reanimated's transform array inference was incorrectly evaluated against DefaultStyle/TextStyle unions

Technical Implementation

flowchart TD
    A[useAnimatedStyle callback] --> B{TypeScript Inference}
    B --> C[Union Type Conflict]
    C --> D[DefaultStyle vs ViewStyle]
    D --> E[TS2345 Error]
    E --> F[Explicit ViewStyle Typing]
    F --> G[Scale Property Casting]
    G --> H[Resolved Type Safety]
Loading

Impact

  • Type Safety: Eliminates TypeScript compilation errors while maintaining strict type checking
  • Developer Experience: Removes confusing type errors that could block development workflow
  • Code Reliability: Ensures transform properties are correctly typed without compromising runtime behavior
  • Backward Compatibility: Changes are purely additive type annotations with no breaking changes to existing functionality

Created with Palmier

…ooks

Explicitly typed the return objects from `useAnimatedStyle` callbacks as `import('react-native').ViewStyle` in `useSlider.ts` and `useScrollHeader.ts`. This resolves TypeScript compiler errors (TS2345) where Reanimated's `transform` array inference was incorrectly evaluated against the `DefaultStyle` / `TextStyle` type due to unions.

Co-authored-by: truongnat <87919564+truongnat@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Apr 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rnui Ready Ready Preview, Comment Apr 30, 2026 4:26pm

@cubic-dev-ai cubic-dev-ai 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 issues found across 2 files

- Explicitly typed the return objects from \`useAnimatedStyle\` callbacks as \`import('react-native').ViewStyle\` in \`useSlider.ts\` and \`useScrollHeader.ts\`. This resolves TypeScript compiler errors (TS2345) where Reanimated's \`transform\` array inference was incorrectly evaluated against the \`DefaultStyle\` / \`TextStyle\` type.
- Updated \`.github/workflows/ci.yml\` to correctly install \`Node.js 22\` for the Docs job since Astro 5.0+ requires it, preventing "Node.js v20.20.2 is not supported by Astro" error.

Co-authored-by: truongnat <87919564+truongnat@users.noreply.github.com>
- Explicitly typed the return objects from \`useAnimatedStyle\` callbacks as \`import('react-native').ViewStyle\` and properly casted \`scale\` properties as \`never\` within \`transform\` to satisfy typescript in \`useSlider.ts\` and \`useScrollHeader.ts\`. This resolves TypeScript compiler errors (TS2345) where Reanimated's \`transform\` array inference was incorrectly evaluated against the \`DefaultStyle\` / \`TextStyle\` type.
- Updated \`.github/workflows/ci.yml\` to correctly install \`Node.js 22\` for the Docs job since Astro 5.0+ requires it, preventing "Node.js v20.20.2 is not supported by Astro" error.
- Fixed \`@truongdq01/ui:test:perf\` by robustly conditionally mocking \`react-native-worklets-core\` in \`packages/ui/jest.setup.ts\` avoiding \`module not found\` errors on CI.

Co-authored-by: truongnat <87919564+truongnat@users.noreply.github.com>
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