You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating a slice for my state, and one of the actions I want to create does not take a payload. However, when mapping the dispatch to the props in connect, I get a weird type error. Argument of type 'typeof MyComponent' is not assignable to parameter of type 'ComponentType<Matching<{ loading: boolean; } & { setLoaded: SliceActionCreator<void>; }, MyProps>>'. Type 'typeof MyComponent' is not assignable to type 'ComponentClass<Matching<{ loading: boolean; } & { setLoaded: SliceActionCreator<void>; }, MyProps>, any>'. Types of parameters 'props' and 'props' are incompatible. Type 'Matching<{ loading: boolean; } & { setLoaded: SliceActionCreator<void>; }, MyProps>' is not assignable to type 'Readonly<MyProps>'. Types of property 'setLoaded' are incompatible. Type 'SliceActionCreator<void>' is not assignable to type '() => void'.
Here's a minimal reproduction of the issue I'm having:
importReact,{PureComponent}from'react';import{createSlice}from'redux-starter-kit';import{connect}from'react-redux'interfaceMyState{loading: boolean;}constINITIAL_STATE: MyState={loading: true,}constslice=createSlice({slice: 'mySlice',initialState: INITIAL_STATE,reducers: {setLoaded: (state)=>{state.loading=false;},}})interfaceMyProps{loading: boolean;setLoaded(): void;}classMyComponentextendsPureComponent<MyProps>{componentDidMount(){// perform some check for loadingconstsetLoaded=this.props.setLoaded;setLoaded();}render(){constloading=this.props.loading;if(loading){return(<p>Loading...</p>);}else{return(<p>Loaded!</p>)}}}exportdefaultconnect((state: MyState)=>({loading: state.loading,}),{setLoaded: slice.actions.setLoaded,})(MyComponent)
If I change the type of the action property in MyProps to take a void payload, then the error goes away, but that's obviously not the correct type:
Am I doing something wrong, or is there a bug in the typing?
The text was updated successfully, but these errors were encountered:
pat-son
changed the title
Issue with ActionCreators from createSlice with no payload
Type issue with ActionCreators from createSlice with no payload
Feb 5, 2019
I am creating a slice for my state, and one of the actions I want to create does not take a payload. However, when mapping the dispatch to the props in
connect
, I get a weird type error.Argument of type 'typeof MyComponent' is not assignable to parameter of type 'ComponentType<Matching<{ loading: boolean; } & { setLoaded: SliceActionCreator<void>; }, MyProps>>'. Type 'typeof MyComponent' is not assignable to type 'ComponentClass<Matching<{ loading: boolean; } & { setLoaded: SliceActionCreator<void>; }, MyProps>, any>'. Types of parameters 'props' and 'props' are incompatible. Type 'Matching<{ loading: boolean; } & { setLoaded: SliceActionCreator<void>; }, MyProps>' is not assignable to type 'Readonly<MyProps>'. Types of property 'setLoaded' are incompatible. Type 'SliceActionCreator<void>' is not assignable to type '() => void'.
Here's a minimal reproduction of the issue I'm having:
If I change the type of the action property in
MyProps
to take a void payload, then the error goes away, but that's obviously not the correct type:Am I doing something wrong, or is there a bug in the typing?
The text was updated successfully, but these errors were encountered: