You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
react-redux type inference is broken since v3.1 #30874
I've noticed this issue while upgrading from v3.0.3. Type inferrence got broken on some of redux's connect calls. I was able to isolate the issue (see the code below). The issue is reproducible on @next and @latest. I ran some regression tests and was able to narrow it down to 3.1.0-dev.20180810 where the bug was introduced. The last version where the code works as expected was 3.1.0-dev.20180809.
Code
typeMapStateToProps<TStateProps>=()=>TStateProps;typeMergeProps<TStateProps,TMergedProps>=(stateProps: TStateProps)=>TMergedProps;functionconnect<TStateProps={},TMergedProps={}>(mapStateToProps: MapStateToProps<TStateProps>,mergeProps: MergeProps<TStateProps,TMergedProps>){}connect(()=>({time: 123}),({ time })=>({
time,doSomething(){},}))
Expected behavior: compiles without errors
Actual behavior:error TS2459: Type 'TStateProps' has no property 'time' and no string index signature.
Somehow these examples compile without problem though:
// no 'expression body' in C# termsconnect(()=>({time: 123}),({ time })=>{return{
time,doSomething(){},}})// no 'time' on TMergedPropsconnect(()=>({time: 123}),({ time })=>({doSomething(){},}))// property instead of a functionconnect(()=>({time: 123}),({ time })=>({
time,doSomething: ()=>{},}))
Activity
Dudeonyx commentedon Apr 13, 2019
Connect works fine for me,
Have you tried updating @types/react-redux ?
Torvin commentedon Aug 1, 2019
Can't reproduce anymore on
3.6.0-dev.20190730. Fixed?jakebailey commentedon Jul 18, 2023
This was fixed by #31574, but could probably use an explicit test.