-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add ComponentType overloading #737
Add ComponentType overloading #737
Conversation
5afeb56
to
d4a2aa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Since migrating from Styled Components I've had to add as ComponentClass<...>
to every single styled()
call with a component, which has gotten really messy and inconvenient. This seems to be the right solutions.
@Ailrun could you fix the merge conflicts? |
d4a2aa8
to
0e3d7ab
Compare
@mitchellhamilton I just did it :) |
@@ -24,7 +24,7 @@ export interface StyledComponentMethods<Props extends object, InnerProps extends | |||
): StyledStatelessComponent<Props, IP, Theme>; | |||
|
|||
withComponent<IP extends object>( | |||
component: ComponentClass<IP>, | |||
component: ComponentClass<IP> | ComponentType<IP>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just looking at the react types and ComponentType
is defined like this
type ComponentType<P = {}> = ComponentClass<P> | StatelessComponent<P>;
So couldn't ComponentClass
be removed here and the other places which are ComponentClass<IP> | ComponentType<IP>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitchellhamilton It is also same in Preact, but I thought this is more clear, since this ComponentType<IP>
is only for the library code who returns ComponentType<IP>
in their code.
@@ -23,7 +23,7 @@ export interface StyledComponentMethods<Props extends object, InnerProps extends | |||
): StyledStatelessComponent<Props, IP, Theme>; | |||
|
|||
withComponent<IP extends object>( | |||
component: ComponentConstructor<IP>, | |||
component: ComponentConstructor<IP> | ComponentFactory<IP>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the previous comment, couldn't this usage and the other just be ComponentFactory<IP>
?
https://github.com/developit/preact/blob/master/src/preact.d.ts#L40
What: Add
ComponentType
/ComponentFactory
cases to styled function overloadings.Why: #736.
How: By adding function overloadings
Checklist: