Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-redux type inference is broken since v3.1 #30874

Open
Torvin opened this issue Apr 12, 2019 · 3 comments
Open

react-redux type inference is broken since v3.1 #30874

Torvin opened this issue Apr 12, 2019 · 3 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@Torvin
Copy link

Torvin commented Apr 12, 2019

TypeScript Version: 3.1.0-dev.20180810

Search Terms: react-redux connect type inference

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

type MapStateToProps<TStateProps> = () => TStateProps;

type MergeProps<TStateProps, TMergedProps> = (stateProps: TStateProps) => TMergedProps;

function connect<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.

Playground Link: here

Somehow these examples compile without problem though:

// no 'expression body' in C# terms
connect(() => ({ time: 123 }), ({ time }) => {
   return {
      time,
      doSomething() {
      },
   }
})

// no 'time' on TMergedProps
connect(() => ({ time: 123 }), ({ time }) => ({
   doSomething() {
   },
}))

// property instead of a function
connect(() => ({ time: 123 }), ({ time }) => ({
   time,
   doSomething: () => {
   },
}))
@Dudeonyx
Copy link

Connect works fine for me,

Have you tried updating @types/react-redux ?

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 16, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Apr 16, 2019
@Torvin
Copy link
Author

Torvin commented Aug 1, 2019

Can't reproduce anymore on 3.6.0-dev.20190730. Fixed?

@jakebailey
Copy link
Member

This was fixed by #31574, but could probably use an explicit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants