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

Type check error in Class based component #138

Open
praburangki opened this issue Feb 16, 2019 · 1 comment
Open

Type check error in Class based component #138

praburangki opened this issue Feb 16, 2019 · 1 comment
Labels
question types TypeScript support

Comments

@praburangki
Copy link

This might be a basic Typescript question but I'm not sure.

I have a container component that is declared like this:

class Container extends Component<any> {
// something
}

const mapStateToProps = ({ search }, { fieldType }) => ({
  fieldSelected: search[fieldType],
});

const mapActionToProps = {
  setSearchField: searchActions().setField,
};

export default connect(
  mapStateToProps,
  mapActionToProps
)(Container);

If I import it with extra props like this:
<Container options={options} fieldType={fieldType} />
It throws a type error. I've noticed that changing to this works:
connect<{}, {}, {}, {}>

When using this format:
const Container: ComponentClass = class extends Component<any>
the type error occurred here:

export default connect(
  mapStateToProps,
  mapActionToProps
)(Container) // <--

Feel free to close this if it is not related.

@developit
Copy link
Owner

I don't think we have a way to infer the types of mapStateToProps and mapActionToProps automatically, so you have to type them and use connect<ContainerProps, ContainerState, StoreState, InjectedProps>.

@developit developit added question types TypeScript support labels Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question types TypeScript support
Projects
None yet
Development

No branches or pull requests

2 participants