JSX element type 'NumberInput' is not a constructor function for JSX elements. Types of property 'setState' are incompatible.
dav-ell opened this issue · comments
Using typescript@2.3.4, webpack@2.6.1, material-ui@^0.18.3, @ types/material-ui@^0.17.11.
Stacktrace:
(99,21): error TS2605: JSX element type 'NumberInput' is not a constructor function for JSX elements.
Types of property 'setState' are incompatible.
Type '{ <K extends never>(f: (prevState: void, props: NumberInputProps) => Pick<void, K>, callback?: ()...' is not assignable to type '{ <K extends never>(f: (prevState: {}, props: any) => Pick<{}, K>, callback?: () => any): void; <...'.
Types of parameters 'f' and 'f' are incompatible.
Type '(prevState: {}, props: any) => Pick<{}, any>' is not assignable to type '(prevState: void, props: NumberInputProps) => Pick<void, any>'.
Types of parameters 'prevState' and 'prevState' are incompatible.
Type 'void' is not assignable to type '{}'.
How I used it:
<NumberInput
required
hintText="Rate ($/hour)"
floatingLabelText="Rate ($/hour)"
strategy="warn"
min={0}
errorText={this.state.rateError}
fullWidth
value={this.state.rate}
onChange={(e: React.FormEvent<HTMLInputElement>, value: string) => this.setState({ rate: value })}
onValid={valid => this.setState({ validRate: valid })}
onRequestValue={value => this.setState({ rate: value })}
onError={this.onError}
/>
I believe this happened on upgrade from @ types/material-ui@^0.17.10 to @ types/material-ui@^0.17.11.
Love the component!
I'm really busy until 12th of july and have no time to fix it ... But I'll accept Pull Request for it.
Added a PR for whenever you have time to check over it.
For posterity, in case anyone comes across a similar problem elsewhere... I think this was the result of a typescript update, not a material-ui types update. The fix was just to change void
to Object
or {}
in certain places that referenced state, such as here:
export class NumberInput extends React.Component<NumberInputProps, void> {
changed to
export class NumberInput extends React.Component<NumberInputProps, Object> {
Maybe typescript became more strict on the way they expect empty props or state to be represented. In any case, this seems to fix it.
Do you know when the update will be published to npm?
I just publish it, sorry for the delay was really busy ....