React+Redux Template does not compile with --strict #44

Closed
opened 2025-08-09 17:14:47 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @MikaelUmaN on 6/7/2018

Happy if someone might point out an obvious fix for this. After creating a project with the template on VS 2017 15.7.1, I get a bunch of errors. Example:

Code in: FetchData.tsx

export default connect(
    (state: ApplicationState) => state.weatherForecasts, // Selects which state properties are merged into the component's props
    WeatherForecastsState.actionCreators                 // Selects which action creators are merged into the component's props
)(FetchData) as typeof FetchData;

With error:

Severity Code Description Project File Line Suppression State
Error TS2345 (TS) Argument of type 'typeof FetchData' is not assignable to parameter of type 'Component'.
Type 'typeof FetchData' is not assignable to type 'StatelessComponent'.
Type 'typeof FetchData' provides no match for the signature '(props: WeatherForecastsState & { children?: ReactNode; }, context?: any): ReactElement | null'. C:\dev\CSharp\ReactRedux (tsconfig or jsconfig project) C:\dev\CSharp\ReactRedux\ClientApp\components\FetchData.tsx 73 Active

I was able to re-write another component into this code which removed the compiler error there.

const mapStateToProps = (state: ApplicationState) => {
    return state.counter
};

const mapDispatchToProps = (dispatch: Dispatch<any>) => {
    return CounterStore.actionCreators
};

// Wire up the React component to the Redux store
export default connect<StateProps, DispatchProps, {}>(mapStateToProps, mapDispatchToProps)(Counter) as typeof Counter;

So my question is what setting I may be missing? Versions are like this:

"@types/history": "4.6.0",
"@types/react": "15.0.35",
"@types/react-dom": "15.5.1",
"@types/react-hot-loader": "3.0.3",
"@types/react-redux": "4.4.45",
"@types/react-router": "4.0.12",
"@types/react-router-dom": "4.0.5",
"@types/react-router-redux": "5.0.3",
"typescript": "2.4.1",
*Originally created by @MikaelUmaN on 6/7/2018* Happy if someone might point out an obvious fix for this. After creating a project with the template on VS 2017 15.7.1, I get a bunch of errors. Example: **Code in: FetchData.tsx** ``` export default connect( (state: ApplicationState) => state.weatherForecasts, // Selects which state properties are merged into the component's props WeatherForecastsState.actionCreators // Selects which action creators are merged into the component's props )(FetchData) as typeof FetchData; ``` **With error:** Severity Code Description Project File Line Suppression State Error TS2345 (TS) Argument of type 'typeof FetchData' is not assignable to parameter of type 'Component<WeatherForecastsState>'. Type 'typeof FetchData' is not assignable to type 'StatelessComponent<WeatherForecastsState>'. Type 'typeof FetchData' provides no match for the signature '(props: WeatherForecastsState & { children?: ReactNode; }, context?: any): ReactElement<any> | null'. C:\dev\CSharp\ReactRedux (tsconfig or jsconfig project) C:\dev\CSharp\ReactRedux\ClientApp\components\FetchData.tsx 73 Active I was able to re-write another component into this code which removed the compiler error there. ``` const mapStateToProps = (state: ApplicationState) => { return state.counter }; const mapDispatchToProps = (dispatch: Dispatch<any>) => { return CounterStore.actionCreators }; // Wire up the React component to the Redux store export default connect<StateProps, DispatchProps, {}>(mapStateToProps, mapDispatchToProps)(Counter) as typeof Counter; ``` So my question is what setting I may be missing? Versions are like this: "@types/history": "4.6.0", "@types/react": "15.0.35", "@types/react-dom": "15.5.1", "@types/react-hot-loader": "3.0.3", "@types/react-redux": "4.4.45", "@types/react-router": "4.0.12", "@types/react-router-dom": "4.0.5", "@types/react-router-redux": "5.0.3", "typescript": "2.4.1",
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#44
No description provided.