You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reason being that it doesn't work properly with class components that have default props:
classFooextendsReact.Component<{bar: number}>{staticdefaultProps={bar: 123,};}constprops: React.ComponentProps<typeofFoo>={};constfoo=<Foo/>; // Of course works
Results in: Property 'bar' is missing in type '{}' but required in type '{ bar: number; }'.ts(2741)
Considering that that discussion about improving ComponentProps I just linked to ended without getting resolved, I'd like to suggest to go with one of the following for this guide:
Instead of ComponentProps, have a code block with a custom type for people to use - possibly the one from the PR (since it does work). (While I personally do this in my projects, it seems to me that you're trying to stick with what's possible out of the box, so this might not be an acceptable solution for this guide, I suppose.)
Completely remove the part about ComponentProps from the README.
Warn about the shortcomings of using the vanilla ComponentProps.
I'd also like to note that there's a second shortcoming to both ComponentProps as well as my enhanced version: It's just not possible to use this with generic class components. Since TS doesn't support something like React.ComponentProps<typeof Foo<string>>. As far as I know. But one of course can export generic prop types.
The text was updated successfully, but these errors were encountered:
Reason being that it doesn't work properly with class components that have default props:
Results in:
Property 'bar' is missing in type '{}' but required in type '{ bar: number; }'.ts(2741)
Also, the team who originally wrote it said it was only supposed to be used internally.
Considering that that discussion about improving
ComponentProps
I just linked to ended without getting resolved, I'd like to suggest to go with one of the following for this guide:ComponentProps
, have a code block with a custom type for people to use - possibly the one from the PR (since it does work). (While I personally do this in my projects, it seems to me that you're trying to stick with what's possible out of the box, so this might not be an acceptable solution for this guide, I suppose.)ComponentProps
from the README.ComponentProps
.I'd also like to note that there's a second shortcoming to both
ComponentProps
as well as my enhanced version: It's just not possible to use this with generic class components. Since TS doesn't support something likeReact.ComponentProps<typeof Foo<string>>
. As far as I know. But one of course can export generic prop types.The text was updated successfully, but these errors were encountered: