aspnet / JavaScriptServices

[Archived] This repository has been archived
Apache License 2.0
3.03k stars 518 forks source link

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

Closed MikaelUmaN closed 6 years ago

MikaelUmaN commented 6 years ago

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",
MikaelUmaN commented 6 years ago

Seems template significantly out of date. Updating typescript and other versions got it working better.