Skip to content

Commit

Permalink
Fix component type in TS typings (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetliakov authored and Kye Hohenberger committed Oct 19, 2017
1 parent 71ba95d commit acfd9a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/react-emotion/typescript_tests/typescript_tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const SFCComponent: React.StatelessComponent<SFCComponentProps> = props => (
<div className={props.className}>{props.children} {props.foo}</div>
);

declare class MyClassC extends React.Component<CustomProps2> { };

// infer SFCComponentProps
Component = styled(SFCComponent)({ color: 'red' });
mount = <Component foo="bar" />;
Expand All @@ -74,6 +76,9 @@ mount = <Component foo="bar" />;
Component = styled(SFCComponent)`color: red`;
mount = <Component foo="bar" />;

Component = styled(MyClassC) ``;
mount = <Component customProp="abc" />;

// do not infer SFCComponentProps with pass CustomProps, need to pass both
Component = styled<CustomProps2 & SFCComponentProps>(SFCComponent)({
color: 'red',
Expand Down
6 changes: 3 additions & 3 deletions packages/react-emotion/typings/react-emotion.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StatelessComponent, Component as ClassComponent, CSSProperties } from 'react'
import { StatelessComponent, ComponentClass, CSSProperties } from 'react'
import { Interpolation as EmotionInterpolation } from 'emotion'

export * from 'emotion'
Expand All @@ -21,7 +21,7 @@ export interface Options {
}

type Component<Props> =
| ClassComponent<Props>
| ComponentClass<Props>
| StatelessComponent<Props>

export type ThemedProps<Props, Theme> = Props & {
Expand All @@ -30,7 +30,7 @@ export type ThemedProps<Props, Theme> = Props & {

export interface StyledComponent<Props, Theme, IntrinsicProps>
extends
ClassComponent<Props & IntrinsicProps>,
ComponentClass<Props & IntrinsicProps>,
StatelessComponent<Props & IntrinsicProps>
{
withComponent<Tag extends keyof JSX.IntrinsicElements>(tag: Tag):
Expand Down

0 comments on commit acfd9a5

Please sign in to comment.