Skip to content

[TypeScript] V9 UseSprings setter definition issue #723

@barrymay

Description

@barrymay

Hi,

I'm trying to use useSprings with Typescript, and the setter seems to be defined incorrectly in the d.ts. This was equally a problem in v8 but my understanding is that you're not taking updates typing there ;)

The useSprings (plural) setting is currently defined like this for v9

export interface SpringUpdateFn<T extends object = {}> {
  /** Update the props of a spring */
  (props: SpringUpdate<T>): void
export type SpringUpdate<T extends object = {}> = Partial<T> &
  SpringProps<{ to: T }> &
  UnknownProps

But it seems to me like it should be this:

export type SpringsUpdateFn<Props extends object = {}> = (
  i: number
) => Props & UseSpringProps<Props>

I tried to create a PR to help here, but I'm getting an error (below) after running thru the contributing script and hooking it into my project:

.../react-spring/packages/core/src/legacy.js
SyntaxError: .../react-spring/packages/core/src/legacy.js: Unexpected token (25:6)

  23 |     const element = is.fun(result) ? result(props) : result
  24 |     return element && element.type ? (
> 25 |       <element.type {...element.props} key={key} ref={element.ref} />
     |       ^
  26 |     ) : (
  27 |       element
  28 |     )

If someone can either help me with the PR building or just make the update themselves, I'd be happy to test it for you. I'm confident on this since my old code that worked on v8 still works on v9, just the typing here is problematic in both versions. (If I'm using it wrong in both, please let me know!)

Thanks,
Barry

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions