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

Aperta
#2,312 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
react, three.js, typescript
Ambito
frontend

Direzione di ricerca

Inizia dai tipi delle props del gruppo animato di @react-spring/three e confronta come sono rappresentati gli array di posizione e rotazione. Usa la riproduzione in TypeScript nell’issue per verificare la discrepanza; il lavoro è completato quando la prop di rotazione mostrata viene compilata senza errori, preservando al contempo il comportamento runtime esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
29.3k
Fork
1.2k
Merge medio
3g 15h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pmndrs/react-spring

Tutte le issue di pmndrs/react-spring

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.