Skip to content

[bug]: Incorrect result type in SpringValue onChange handler #2183

@mattrossman

Description

@mattrossman

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.3

What's Wrong?

The onChange option in the SpringValue constructor indicates that the argument is of type AnimationResult<SpringValue<number>>

CleanShot 2023-08-03 at 13 48 53@2x

Thus, result.value is indicated to be of type number, and logging this should display the animated value. However, it actually prints undefined as the spring animates:

CleanShot 2023-08-03 at 13 49 39@2x

If I instead log the entire result, I see the number.

To Reproduce

import { SpringValue } from '@react-spring/web'

const spring = new SpringValue(0, {
 onChange(result) {
  console.log(result.value)
 }
})

spring.start(1)

Expected Behaviour

I expect to see the value on result.value, which TypeScript indicates is a number

Link to repo

https://codesandbox.io/s/vigorous-mirzakhani-qrrwj8?file=/src/App.tsx

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions