#StackBounty: #typescript #redux #react-redux #typescript-typings #.d.ts redux's inferred type in .d.ts doesn't match my VSCode…

Bounty: 50

This is what I have; simple stuff.

interface quote {
  quote: string
  author: string
}

interface StoreState {
  quote: {
    quotes: any[]
  }
}
const mapStateToProps = (state: StoreState) => {
  return {
    quotes: state.quote.quotes,
  }
}

const mapDispatchToProps = (dispatch: Dispatch<AnyAction>) => {   return {
    addQuote: (quote: quote) => dispatch(addQuoteAction(quote)),
    clearQuotes: () => dispatch(clearQuotesAction()),
    deleteQuote: (author: string) => dispatch(deleteQuoteAction(author)),   } }

export default connect(mapStateToProps, mapDispatchToProps)

But the result in d.ts completely forgot about the stuff in mapStateToProps.

enter image description here

This is what my VSCode’s type hint shows (which shows yeah, the type from mapStateToProps (e.g. in this case, quotes: any[]) should be a part of the type param):

enter image description here

I’m using typescript’s .createLanguageService to directly generate the d.ts. Just wondering why the type from mapStateToProps got ignored.

If I write

export default connect(mapStateToProps)

then yup d.ts got the right type from mapStateToProps:

enter image description here

I’m not concerned with the type of connect(mapStateToProps, mapDispatchToProps)(App) but I’m interested to get the correct type for connect(mapStateToProps, mapDispatchToProps).

Also sometimes I do get the right type with mapStateToProps but I’m not consistently getting it.

(could it have something to do with how things are defined in DefinitelyTyped?)


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.