[bug]: type error: animated group rotation prop does not accept array or euler object

Open
#2,312 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, three.js, typescript
Domain
frontend

Research direction

Start with the @react-spring/three animated group prop typings and compare how position and rotation arrays are represented. Use the TypeScript reproduction in the issue to verify the mismatch; done means the shown rotation prop compiles without an error while preserving the existing runtime behavior.

Written by the indexing model from the issue text.

Description

area: three kind: bug
Which react-spring target are you using?
  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog
What version of react-spring are you using?

9.7.4

What's Wrong?

When I use spring to animate the rotation of a three.js object, typescript throws a type error when the rotation prop is provided as an array while using the position prop works as expected with an array but applying the same logic to rotation results in a type mismatch.

To Reproduce

Here is a simple example

import { animated, useSpring } from '@react-spring/three';
import { Box } from '@react-three/drei';
import { Canvas } from '@react-three/fiber';
import { useState } from 'react';

const RotatingCube = () => {
    const [clicked, setClicked] = useState(false);
    // Define spring for position and rotation
    const { position, rotation } = useSpring({
        position: [0, 0, 0] as const, // Static position
        rotation: clicked ?
                   ([Math.PI / 4, Math.PI / 4, 0] as const)
                 : ([Math.PI / 2, Math.PI / 4, 0] as const)
    });

    return (
        <animated.group
            position={position}
            rotation={rotation} // This triggers the type error
        >
            <Box onClick={() => setClicked((clicked) => !clicked)}>
                <meshStandardMaterial attach="material" color="orange" />
            </Box>
        </animated.group>
    );
};

const Root = () => {
    return (
        <Canvas>
            <ambientLight />
            <pointLight position={[10, 10, 10]} />
            <RotatingCube />
        </Canvas>
    );
};

export default Root;
Expected Behaviour

I expect the code to compile with no issues since it also works at runtime.

Link to repo

See To Reproduce section

Dominant language
TypeScript
Stars
29.3k
Forks
1.2k
Avg merge
3d 15h
Merged PRs (30d)
17

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pmndrs/react-spring

All issues in pmndrs/react-spring

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.