Skip to content
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

Merged

Conversation

Ailrun
Copy link
Member

@Ailrun Ailrun commented Jun 20, 2018

What: Add ComponentType/ComponentFactory cases to styled function overloadings.

Why: #736.

How: By adding function overloadings

Checklist:

  • [N/A] Documentation
  • Tests
  • Code complete

@Ailrun Ailrun self-assigned this Jun 20, 2018
@Ailrun Ailrun force-pushed the typings/add-overloading-for-component-type branch 2 times, most recently from 5afeb56 to d4a2aa8 Compare June 20, 2018 19:28
Copy link

@nickmccurdy nickmccurdy left a 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.

@emmatown
Copy link
Member

emmatown commented Jul 6, 2018

@Ailrun could you fix the merge conflicts?

@Ailrun Ailrun force-pushed the typings/add-overloading-for-component-type branch from d4a2aa8 to 0e3d7ab Compare July 6, 2018 22:19
@Ailrun
Copy link
Member Author

Ailrun commented Jul 6, 2018

@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>,
Copy link
Member

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>?

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a5b0278214093cc8714871d1db74bb53ed0b7e76/types/react/index.d.ts#L51

Copy link
Member Author

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>,
Copy link
Member

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

@emmatown emmatown merged commit 0c78202 into emotion-js:master Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants