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
React 0.13 - Component vs ComponentClass #3978
Comments
May I recommend creating factories? I think you'll find the type errors to be a little more useful. eg: var button = React.createFactory(Button);
button({ happy: 3 }); which should give you
|
Thank you for the reply! =) I tried to use factories, here is a more condensed example of what I'm guessing is the same underlying problem. To my understanding, createFactory does not actually recognize Component, only string, ComponentClass and ClassicComponent. Shouldn't createElement, and createFactory be overloaded to also take Component then? The following will yield the same error, 'Argument of type "typeof Button' is not assignable to parameter of type 'string'"
The error does not occur if I remove the optional modifier on color, or if I use createFactory , |
You need to explicitly type-annotate static defaultProps: P = I think that will fix it. btw, here's a handy reference for React types: ComponentClass<P> --> --> ReactElement<P> --> --> Component<P, S>
ClassicComponentClass<P> --> React.createElement --> ClassicElement<P> --> React.render --> ClassicComponent<P, S>
string --> --> DOMElement<P> --> --> DOMComponent<P> |
Well that worked! Thank you, you're awesome. ^_^ |
Great! I'm glad that worked out. |
great, I couldn't figure out how to use defaultProps, but making it a static property and setting its type fixed it. Thank you for the clarification on the react types too, very helpful! |
Here is what I am doing to get my static properties, as defined by // error as expected, displayName should be string
const ReactComponent: ComponentClass<any> = class extends Component<any, any> {
static displayName = 1
render() {
return <div>{this.props.name}</div>
}
}; I think in the ideal case there would be no |
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
Hi.
I might be mistaken, but shouldn´t class Component implement ComponentClass?
Here's an example, it compiles using TS 1.4, and runs as expected with React 0.13.1 - but if I replace any with P I get ""Argument of type 'typeof Button is not assignable to type 'string'"" because the overload on createElement cannot find a better match.
The text was updated successfully, but these errors were encountered: