Typescript & Redux connect
I'm trying to connect redux to a component using Typescript and keep running into the same error.
Argument of type 'typeof BaseLayoutUnconnected' is not assignable to
parameter of type 'Component < any, {}, any>'. Property 'setState' is
missing in type 'typeof BaseLayoutUnconnected'.
import * as React from 'react';
import { IBaseLayoutProps, IBaseLayoutState } from './base-layout.types';
import { ChatContainer } from '../../components';
import { connect, DispatchProp } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { RouteComponentProps } from 'react-router';
import { ChatActions } from 'app/actions';
import { RootState } from 'app/reducers';
import { omit } from 'app/utils';
export const mapStateToProps = (state: RootState, ownProps) => {
return {
chatItems: state.chatItems
};
};
export const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export class BaseLayoutUnconnected extends React.Component<IBaseLayoutProps, IBaseLayoutState> {
constructor(props) {
super(props);
this.state = {};
}
render() {
const { actions, chatItems } = this.props;
return <ChatContainer actions={actions} chatItems={chatItems} />;
}
}
export const BaseLayout = connect(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected);
This is being called in my app.tsx via
<Route exact={true} path="/" component={BaseLayout} />
Here are the props and state
export interface IBaseLayoutProps {
chatItems: RootState.ChatState;
actions: ChatActions;
}
export interface IBaseLayoutState {}
ChatActions looks like
import { createAction } from 'redux-actions';
import { ChatItemModel } from 'app/models';
export namespace ChatActions {
export enum Type {
ADD_CHAT_ITEM = 'ADD_CHAT_ITEM'
}
export const addChatItem = createAction<PartialPick<ChatItemModel, 'text'>>(Type.ADD_CHAT_ITEM);
}
export type ChatActions = Omit<typeof ChatActions, 'Type'>;
reactjs typescript redux react-redux
add a comment |
I'm trying to connect redux to a component using Typescript and keep running into the same error.
Argument of type 'typeof BaseLayoutUnconnected' is not assignable to
parameter of type 'Component < any, {}, any>'. Property 'setState' is
missing in type 'typeof BaseLayoutUnconnected'.
import * as React from 'react';
import { IBaseLayoutProps, IBaseLayoutState } from './base-layout.types';
import { ChatContainer } from '../../components';
import { connect, DispatchProp } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { RouteComponentProps } from 'react-router';
import { ChatActions } from 'app/actions';
import { RootState } from 'app/reducers';
import { omit } from 'app/utils';
export const mapStateToProps = (state: RootState, ownProps) => {
return {
chatItems: state.chatItems
};
};
export const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export class BaseLayoutUnconnected extends React.Component<IBaseLayoutProps, IBaseLayoutState> {
constructor(props) {
super(props);
this.state = {};
}
render() {
const { actions, chatItems } = this.props;
return <ChatContainer actions={actions} chatItems={chatItems} />;
}
}
export const BaseLayout = connect(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected);
This is being called in my app.tsx via
<Route exact={true} path="/" component={BaseLayout} />
Here are the props and state
export interface IBaseLayoutProps {
chatItems: RootState.ChatState;
actions: ChatActions;
}
export interface IBaseLayoutState {}
ChatActions looks like
import { createAction } from 'redux-actions';
import { ChatItemModel } from 'app/models';
export namespace ChatActions {
export enum Type {
ADD_CHAT_ITEM = 'ADD_CHAT_ITEM'
}
export const addChatItem = createAction<PartialPick<ChatItemModel, 'text'>>(Type.ADD_CHAT_ITEM);
}
export type ChatActions = Omit<typeof ChatActions, 'Type'>;
reactjs typescript redux react-redux
try to add default values forthis.state
– Medet Tleukabiluly
Nov 20 '18 at 19:14
Adding constructor(props) { super(props); this.state = {}; } doesn't fix the issue. Edited the original question to include that.
– dliebeskind
Nov 20 '18 at 19:18
add a comment |
I'm trying to connect redux to a component using Typescript and keep running into the same error.
Argument of type 'typeof BaseLayoutUnconnected' is not assignable to
parameter of type 'Component < any, {}, any>'. Property 'setState' is
missing in type 'typeof BaseLayoutUnconnected'.
import * as React from 'react';
import { IBaseLayoutProps, IBaseLayoutState } from './base-layout.types';
import { ChatContainer } from '../../components';
import { connect, DispatchProp } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { RouteComponentProps } from 'react-router';
import { ChatActions } from 'app/actions';
import { RootState } from 'app/reducers';
import { omit } from 'app/utils';
export const mapStateToProps = (state: RootState, ownProps) => {
return {
chatItems: state.chatItems
};
};
export const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export class BaseLayoutUnconnected extends React.Component<IBaseLayoutProps, IBaseLayoutState> {
constructor(props) {
super(props);
this.state = {};
}
render() {
const { actions, chatItems } = this.props;
return <ChatContainer actions={actions} chatItems={chatItems} />;
}
}
export const BaseLayout = connect(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected);
This is being called in my app.tsx via
<Route exact={true} path="/" component={BaseLayout} />
Here are the props and state
export interface IBaseLayoutProps {
chatItems: RootState.ChatState;
actions: ChatActions;
}
export interface IBaseLayoutState {}
ChatActions looks like
import { createAction } from 'redux-actions';
import { ChatItemModel } from 'app/models';
export namespace ChatActions {
export enum Type {
ADD_CHAT_ITEM = 'ADD_CHAT_ITEM'
}
export const addChatItem = createAction<PartialPick<ChatItemModel, 'text'>>(Type.ADD_CHAT_ITEM);
}
export type ChatActions = Omit<typeof ChatActions, 'Type'>;
reactjs typescript redux react-redux
I'm trying to connect redux to a component using Typescript and keep running into the same error.
Argument of type 'typeof BaseLayoutUnconnected' is not assignable to
parameter of type 'Component < any, {}, any>'. Property 'setState' is
missing in type 'typeof BaseLayoutUnconnected'.
import * as React from 'react';
import { IBaseLayoutProps, IBaseLayoutState } from './base-layout.types';
import { ChatContainer } from '../../components';
import { connect, DispatchProp } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
import { RouteComponentProps } from 'react-router';
import { ChatActions } from 'app/actions';
import { RootState } from 'app/reducers';
import { omit } from 'app/utils';
export const mapStateToProps = (state: RootState, ownProps) => {
return {
chatItems: state.chatItems
};
};
export const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export class BaseLayoutUnconnected extends React.Component<IBaseLayoutProps, IBaseLayoutState> {
constructor(props) {
super(props);
this.state = {};
}
render() {
const { actions, chatItems } = this.props;
return <ChatContainer actions={actions} chatItems={chatItems} />;
}
}
export const BaseLayout = connect(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected);
This is being called in my app.tsx via
<Route exact={true} path="/" component={BaseLayout} />
Here are the props and state
export interface IBaseLayoutProps {
chatItems: RootState.ChatState;
actions: ChatActions;
}
export interface IBaseLayoutState {}
ChatActions looks like
import { createAction } from 'redux-actions';
import { ChatItemModel } from 'app/models';
export namespace ChatActions {
export enum Type {
ADD_CHAT_ITEM = 'ADD_CHAT_ITEM'
}
export const addChatItem = createAction<PartialPick<ChatItemModel, 'text'>>(Type.ADD_CHAT_ITEM);
}
export type ChatActions = Omit<typeof ChatActions, 'Type'>;
reactjs typescript redux react-redux
reactjs typescript redux react-redux
edited Nov 20 '18 at 19:19
dliebeskind
asked Nov 20 '18 at 19:06
dliebeskinddliebeskind
569
569
try to add default values forthis.state
– Medet Tleukabiluly
Nov 20 '18 at 19:14
Adding constructor(props) { super(props); this.state = {}; } doesn't fix the issue. Edited the original question to include that.
– dliebeskind
Nov 20 '18 at 19:18
add a comment |
try to add default values forthis.state
– Medet Tleukabiluly
Nov 20 '18 at 19:14
Adding constructor(props) { super(props); this.state = {}; } doesn't fix the issue. Edited the original question to include that.
– dliebeskind
Nov 20 '18 at 19:18
try to add default values for
this.state
– Medet Tleukabiluly
Nov 20 '18 at 19:14
try to add default values for
this.state
– Medet Tleukabiluly
Nov 20 '18 at 19:14
Adding constructor(props) { super(props); this.state = {}; } doesn't fix the issue. Edited the original question to include that.
– dliebeskind
Nov 20 '18 at 19:18
Adding constructor(props) { super(props); this.state = {}; } doesn't fix the issue. Edited the original question to include that.
– dliebeskind
Nov 20 '18 at 19:18
add a comment |
1 Answer
1
active
oldest
votes
That's a problem i had too when i first started with Redux and TypeScript. There is a tricky solution. The connect methode takes alot of generics. I try to explain it with your example.
First of all you have to split the properties of your BaseLayoutUnconnected.
export interface IBaseLayoutStateProps {
chatItems: RootState.ChatState;
}
export interface IBaseLayoutDispatchProps {
actions: ChatActions;
}
export interface IBaseLayoutOwnProps {
// put properties here you want to make available from the connected component
}
export type IBaseLayoutProps = IBaseLayoutOwnProps & IBaseLayoutDispatchProps & IBaseLayoutStateProps
export interface IBaseLayoutState {}
Then you have to fill the generics of the different redux functions.
const mapStateToProps: MapStateToProps<IBaseLayoutStateProps, {}, RootState> = (state: RootState): IBaseLayoutStateProps => ({
chatItems: state.chatItems
})
export const mapDispatchToProps: MapDispatchToPropsFunction<IBaseLayoutDispatchProps, IBaseLayoutOwnProps> = (dispatch: Dispatch, ownProps: IBaseLayoutDispatchProps): IBaseLayoutDispatchProps => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export default connect<IBaseLayoutStateProps , IBaseLayoutDispatchProps, IBaseLayoutOwnProps , RootState>(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected as any)
a good source, where you can find all this stuff i wrote and more is this repository
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
1
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399878%2ftypescript-redux-connect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's a problem i had too when i first started with Redux and TypeScript. There is a tricky solution. The connect methode takes alot of generics. I try to explain it with your example.
First of all you have to split the properties of your BaseLayoutUnconnected.
export interface IBaseLayoutStateProps {
chatItems: RootState.ChatState;
}
export interface IBaseLayoutDispatchProps {
actions: ChatActions;
}
export interface IBaseLayoutOwnProps {
// put properties here you want to make available from the connected component
}
export type IBaseLayoutProps = IBaseLayoutOwnProps & IBaseLayoutDispatchProps & IBaseLayoutStateProps
export interface IBaseLayoutState {}
Then you have to fill the generics of the different redux functions.
const mapStateToProps: MapStateToProps<IBaseLayoutStateProps, {}, RootState> = (state: RootState): IBaseLayoutStateProps => ({
chatItems: state.chatItems
})
export const mapDispatchToProps: MapDispatchToPropsFunction<IBaseLayoutDispatchProps, IBaseLayoutOwnProps> = (dispatch: Dispatch, ownProps: IBaseLayoutDispatchProps): IBaseLayoutDispatchProps => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export default connect<IBaseLayoutStateProps , IBaseLayoutDispatchProps, IBaseLayoutOwnProps , RootState>(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected as any)
a good source, where you can find all this stuff i wrote and more is this repository
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
1
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
|
show 1 more comment
That's a problem i had too when i first started with Redux and TypeScript. There is a tricky solution. The connect methode takes alot of generics. I try to explain it with your example.
First of all you have to split the properties of your BaseLayoutUnconnected.
export interface IBaseLayoutStateProps {
chatItems: RootState.ChatState;
}
export interface IBaseLayoutDispatchProps {
actions: ChatActions;
}
export interface IBaseLayoutOwnProps {
// put properties here you want to make available from the connected component
}
export type IBaseLayoutProps = IBaseLayoutOwnProps & IBaseLayoutDispatchProps & IBaseLayoutStateProps
export interface IBaseLayoutState {}
Then you have to fill the generics of the different redux functions.
const mapStateToProps: MapStateToProps<IBaseLayoutStateProps, {}, RootState> = (state: RootState): IBaseLayoutStateProps => ({
chatItems: state.chatItems
})
export const mapDispatchToProps: MapDispatchToPropsFunction<IBaseLayoutDispatchProps, IBaseLayoutOwnProps> = (dispatch: Dispatch, ownProps: IBaseLayoutDispatchProps): IBaseLayoutDispatchProps => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export default connect<IBaseLayoutStateProps , IBaseLayoutDispatchProps, IBaseLayoutOwnProps , RootState>(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected as any)
a good source, where you can find all this stuff i wrote and more is this repository
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
1
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
|
show 1 more comment
That's a problem i had too when i first started with Redux and TypeScript. There is a tricky solution. The connect methode takes alot of generics. I try to explain it with your example.
First of all you have to split the properties of your BaseLayoutUnconnected.
export interface IBaseLayoutStateProps {
chatItems: RootState.ChatState;
}
export interface IBaseLayoutDispatchProps {
actions: ChatActions;
}
export interface IBaseLayoutOwnProps {
// put properties here you want to make available from the connected component
}
export type IBaseLayoutProps = IBaseLayoutOwnProps & IBaseLayoutDispatchProps & IBaseLayoutStateProps
export interface IBaseLayoutState {}
Then you have to fill the generics of the different redux functions.
const mapStateToProps: MapStateToProps<IBaseLayoutStateProps, {}, RootState> = (state: RootState): IBaseLayoutStateProps => ({
chatItems: state.chatItems
})
export const mapDispatchToProps: MapDispatchToPropsFunction<IBaseLayoutDispatchProps, IBaseLayoutOwnProps> = (dispatch: Dispatch, ownProps: IBaseLayoutDispatchProps): IBaseLayoutDispatchProps => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export default connect<IBaseLayoutStateProps , IBaseLayoutDispatchProps, IBaseLayoutOwnProps , RootState>(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected as any)
a good source, where you can find all this stuff i wrote and more is this repository
That's a problem i had too when i first started with Redux and TypeScript. There is a tricky solution. The connect methode takes alot of generics. I try to explain it with your example.
First of all you have to split the properties of your BaseLayoutUnconnected.
export interface IBaseLayoutStateProps {
chatItems: RootState.ChatState;
}
export interface IBaseLayoutDispatchProps {
actions: ChatActions;
}
export interface IBaseLayoutOwnProps {
// put properties here you want to make available from the connected component
}
export type IBaseLayoutProps = IBaseLayoutOwnProps & IBaseLayoutDispatchProps & IBaseLayoutStateProps
export interface IBaseLayoutState {}
Then you have to fill the generics of the different redux functions.
const mapStateToProps: MapStateToProps<IBaseLayoutStateProps, {}, RootState> = (state: RootState): IBaseLayoutStateProps => ({
chatItems: state.chatItems
})
export const mapDispatchToProps: MapDispatchToPropsFunction<IBaseLayoutDispatchProps, IBaseLayoutOwnProps> = (dispatch: Dispatch, ownProps: IBaseLayoutDispatchProps): IBaseLayoutDispatchProps => ({
actions: bindActionCreators(omit(ChatActions, 'Type'), dispatch)
});
export default connect<IBaseLayoutStateProps , IBaseLayoutDispatchProps, IBaseLayoutOwnProps , RootState>(
mapStateToProps,
mapDispatchToProps
)(BaseLayoutUnconnected as any)
a good source, where you can find all this stuff i wrote and more is this repository
edited Nov 21 '18 at 21:15
dliebeskind
569
569
answered Nov 20 '18 at 19:24
Sly321Sly321
458312
458312
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
1
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
|
show 1 more comment
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
1
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Thanks @Sly321. Changed everything as you suggested, but getting similar error. It now says "Argument of type 'typeof BaseLayoutUnconnected' is not assignable to parameter of type 'Component < IBaseLayoutOwnProps, {}, any>'. Property 'setState' is missing in type 'typeof BaseLayoutUnconnected'."
– dliebeskind
Nov 20 '18 at 19:43
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
Where do you get the error? In the Router or in the Connect function? Do you have a repository where i can checkout the source?
– Sly321
Nov 20 '18 at 21:41
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
the error is occuring in the connect function. BaseLayoutUnconnected (in the connect function) is underlined.
– dliebeskind
Nov 20 '18 at 23:01
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
Since there is nothing missing in your code in my opinion, do you have all the requirements in your package.json? I'll post some package versions that work for me. "react":"16.4.2" "react-dom":"16.4.2" "react-redux":"5.0.7" "redux":"4.0.0" "@types/react-dom": "16.0.7" "@types/react-redux": "6.0.6" "@types/react-router-dom":"4.3.0" I don't have @types/react in this configuration, BUT i would definitly try out to add @types/react if there is a chance. A good idea is the command: yarn why @types/react try to find out if there a sideeffects from other packages
– Sly321
Nov 21 '18 at 0:42
1
1
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
Another idea, try to call BaseLayoutUnconnect in the connect like this connect<generics & stuff>(mapStateToProps, mapDispatchToProps)(BaseLayoutUnconnect as any as React.Component). If this still errors, then is something wrong with your @types configuration
– Sly321
Nov 21 '18 at 0:54
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399878%2ftypescript-redux-connect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try to add default values for
this.state
– Medet Tleukabiluly
Nov 20 '18 at 19:14
Adding constructor(props) { super(props); this.state = {}; } doesn't fix the issue. Edited the original question to include that.
– dliebeskind
Nov 20 '18 at 19:18