I get this compile error during npm start:
./src/index.tsx
(16,5): error TS2605: JSX element type 'App' is not a constructor function for JSX elements.
Types of property 'setState' are incompatible.
Type '{ <K extends never>(f: (prevState: null, props: {}) => Pick<null, K>, callback?: (() => any) | un...' is not assignable to type '{ <K extends never>(f: (prevState: {}, props: any) => Pick<{}, K>, callback?: (() => any) | undef...'.
Types of parameters 'f' and 'f' are incompatible.
Type '(prevState: {}, props: any) => Pick<{}, any>' is not assignable to type '(prevState: null, props: {}) => Pick<null, any>'.
Types of parameters 'prevState' and 'prevState' are incompatible.
Type 'null' is not assignable to type '{}'.
My code:
class App extends React.Component<{}, null> {
render() {
return (
<div className="App">
...
</div>
);
}
}
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root') as HTMLElement
);
I am using:
node v6.11.0
npm v5.1.0
typescript v2.4.1
react v15.6.1
redux v3.7.1
react-redux v5.0.5
react-scripts-ts v2.3.2
I found out that removing the generic types <{}, null> following React.Component clears the error. But I'd still love to learn why I was getting the error.
The state type (second generic) cannot be null - that's why you were getting the error.
Thanks!
For future readers, I also asked a SO question here: https://stackoverflow.com/q/45024559/1270459
Most helpful comment
The state type (second generic) cannot be null - that's why you were getting the error.