-
Notifications
You must be signed in to change notification settings - Fork 674
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
No overload matches this call error for createStructuredSelector with typescript. #428
Comments
Hi, Got exactly the same issue on the 'header' property from object passed to createStructuredSelector in index.tsx.
index.tsx import React from 'react';
import { Dispatch, AnyAction, bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { getHomeHeaderRequest } from 'stores/actions/home.actions';
import { createStructuredSelector } from 'reselect';
import { selectHeader } from 'stores/selectors/home.selectors';
const mapStateToProps = () =>
createStructuredSelector({
header: selectHeader,
});
const mapDispatchToProps = (dispatch: Dispatch<AnyAction>) =>
bindActionCreators(
{
getHomeHeader: getHomeHeaderRequest,
},
dispatch,
);
type HomeProps = ReturnType<typeof mapStateToProps> &
ReturnType<typeof mapDispatchToProps>;
class Home extends React.Component<HomeProps, {}> {
componentDidMount() {
const { getHomeHeader } = this.props;
getHomeHeader();
}
render() {
const { header } = this.props;
console.log(this.props);
return (
<div>
<p>Hello from {header.title} page</p>
</div>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Home); selectors.ts import { createSelector } from 'reselect';
import { AppState } from 'stores/rootReducer';
import { homeReducerInitialState } from 'stores/reducers/home.reducer';
/* eslint-disable import/prefer-default-export */
const selectHomeStore = (state: AppState) =>
state.Home || homeReducerInitialState;
export const selectHeader = createSelector(
selectHomeStore,
homeState => homeState.header,
); However, the code is working fine. It's just boring to have that typescript error. |
I just figured it out const structuredSelector = createStructuredSelector<
ReduxState, { isTimerStart: boolean; timeleft: number; isInterval: boolean }
>({
isTimerStart: selectIsTimerStart,
timeleft: selectTimeleft,
isInterval: selectIsInterval
}); You can also do just like that: const structuredSelector = createStructuredSelector<any, any>({
isTimerStart: selectIsTimerStart,
timeleft: selectTimeleft,
isInterval: selectIsInterval
}); But i dont think it's a good solution |
@drillprop Thank that's starting to be better Can you tell me why const mapStateToProps = () =>
createStructuredSelector<
AppState,
{ header: HomeHeader; isLoading: boolean }
>({
header: selectHeader,
isLoading: selectLoading,
}); is working ? But why const mapStateToProps = () =>
createStructuredSelector<AppState, HomeSelectors>({
header: selectHeader,
isLoading: selectLoading,
}); export interface HomeSelectors {
header: HomeHeader;
isLoading: boolean;
} tells me that header or isLoading prop does not exist ? Also tested with HomeSelectors as a type. I would like to pass an interface or a type. EDIT: My props are defined that way type HomeProps = ReturnType<typeof mapStateToProps> &
ReturnType<typeof mapDispatchToProps>; EDIT 2: const mapStateToProps = () =>
createStructuredSelector<AppState, HomeSelectors>({
header: selectHeader,
isLoading: selectLoading,
});
type HomeProps = HomeSelectors & ReturnType<typeof mapDispatchToProps>; Thank you for the help 🙂 |
I'm using this type instead of the builtin one: type CeateStructuredSelector = <SelectorMap extends { [key: string]: (...args: any[]) => any }>(
selectorMap: SelectorMap
) => (
state: SelectorMap[keyof SelectorMap] extends (state: infer State) => unknown ? State : never
) => {
[Key in keyof SelectorMap]: ReturnType<SelectorMap[Key]>;
}; Sorry, it doesn't support parametric stuff or some other options, but it should be possible to extend it if you need it. I might submit this as a PR later. |
If you don't want to have to manually specify the generic types, please have a look at the snippet provided in #476. This allows the types to be derived automatically and I hope it works for you. |
I just published https://github.com/reduxjs/reselect/releases/tag/v4.1.0-alpha.0 , which should fix this issue. Can folks try it out and give us feedback? |
Should be fixed by #486 . |
Hi, I am trying to build an react redux typescript app.
I am using reslect library to create selectors.
I am getting an error while using createStructuredSlectore. Please find the error beolow.
Error: No overload matches this call
Please find the code below:
Slectors.ts
cart.reducer.ts
also It is good to have an example.
The text was updated successfully, but these errors were encountered: