react-spring
react-spring copied to clipboard
[bug]: TS < 4.8 project no longer compiles with spring ~9.5
Which react-spring target are you using?
- [X]
@react-spring/web - [ ]
@react-spring/three - [ ]
@react-spring/native - [ ]
@react-spring/konva - [ ]
@react-spring/zdog
What version of react-spring are you using?
9.5.4
What's Wrong?
Due to the changes in #196, backwards compatibility appears to break. Trying to compile the project on TS 4.2.4 gives ~40 errors from react-spring
> node node_modules/.bin/tsc --project tsconfig.json --noEmit --pretty
node_modules/@react-spring/core/dist/declarations/src/hooks/useSpring.d.ts:8:116 - error TS1005: '?' expected.
8 export declare type UseSpringProps<Props extends object = any> = unknown & PickAnimated<Props> extends infer State extends Lookup<any> ? Remap<ControllerUpdate<State> & {
~~~~~~~
node_modules/@react-spring/core/dist/declarations/src/hooks/useSpring.d.ts:8:124 - error TS1005: ':' expected.
8 export declare type UseSpringProps<Props extends object = any> = unknown & PickAnimated<Props> extends infer State extends Lookup<any> ? Remap<ControllerUpdate<State> & { ~~~~~~
I think this was unintentional as the fix was to support TS 4.8 (not remove support for older TS), but perhaps should have been released as a major version. We're on 4.2.4 and can no longer compile our project with these changes. Additionally, because react-spring has dependencies set to ~9.5.2, all new installs will also pull 9.5.4 meaning people must peg all dependencies in their package files:
"@react-spring/types": "9.5.2",
"@react-spring/web": "9.5.2",
"@react-spring/animated": "9.5.2",
"@react-spring/core": "9.5.2",
"@react-spring/shared": "9.5.2",
NOTE: I did not test other TS versions between 4.8, so it's possible that it works on 4.3 even
To Reproduce
- Add react-spring 9.5.2 to a project using ts 4.2.3
Expected Behaviour
react-spring should be compilable or have specified TS dependency ranges.
Various workarounds are likely possible, but the ergonomics are a little funky.
Link to repo
Don't have
Hm, Id be interested in hearing suggestions on how to support this because it felt like from the TS side, extending an infered value was the correct way to go.
Without a suggestion I am unsure how to proceed, maybe there's a "polyfill" approach?
I wish I had a more concrete suggestion, obviously with us being behind the ball on TS 4.3, I haven't encountered the migration path for TS and am not an expert on the newer changes there. Obviously finding a forward/backward compatible path would be great, I just don't even know what to look for (and the code edited looks moderately complex).
But barring that, I also think it's valid to undo the changes on v9 and peg v9 to TS <4.8, and then release a v10 with TS >= 4.8. Just might be overkill if there is a forward/backward compatible way to phrase those particular TS expressions.
This seems to be the hangup in other repos: https://devblogs.microsoft.com/typescript/announcing-typescript-4-8-beta/#unconstrained-generics-no-longer-assignable-to, have seen a few TS contributors fixing various projects.
i've released this in a beta – 9.5.5-beta.0 it'd be great if you could give that a go in your codebase to see if it resolves you're issue!
Installed and typecheck seems to run OK! Thanks :)