-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This type is incompatible with some incompatible instantiation #3091
Comments
I am also seeing same error for // @flow
import React, { Component } from 'react'
type BaseProps = {
name: string
}
type BaseState<T> = {
error: string,
value: ?T,
}
class Base<Props, V> extends Component<any, BaseProps & Props, BaseState<V>> {
state = {
error: '',
value: null,
}
render() {
return <div>this.props.name</div>
}
}
type ExtendedProps = {
foo: string,
}
class ExtendedBase extends Base<ExtendedProps, string> {
render () {
return <div>this.props.name</div>
}
} 14: class Base<Props, V> extends Component<any, BaseProps & Props, BaseState> { |
Thanks @ryyppy. Defining type of state on the class seems to do the trick. Is that always required? Or only with generics? |
For classes, I really really recommend to always add the class property types EDIT: Also, I really urge you to not do subclassing like this... use higher order components instead, it makes the code much more reasonable and easier to extend! |
@jinxac Anything else left to discuss? Or can we close this issue? |
Thanks again @ryyppy. Just messing around with generics at this point. Agreed about using HOCs. |
@ryyppy this code looks exactly similar to mine, but with one difference. I see in my code constructor is defined as
I saw the above in polymorphic classes docs. In docs its
But if i add the annotation in the constructor parameter, this seems to be work fine.
|
Yes I am closing this. raised a pull request in flow repository for this issue. |
I was trying following code.
Its a pretty simple code in which I create a polymorphic class and just extend giving it type
number
. But i continuously get following errorIt should work I feel? Can someone please tell if I am going wrong or something needs to be fixed?
The text was updated successfully, but these errors were encountered: