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

Added TypeScript definitions for innerRef. #426

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/react-emotion/typescript_tests/typescript_tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,19 @@ mount = <Button type="submit" bgColor="red" />;
*/

flush();

/**
* innerRef
*/

Component = styled('div')``;
mount = <Component innerRef={(element: HTMLDivElement) => {}} />;

Component = styled.div``;
mount = <Component innerRef={(element: HTMLDivElement) => {}} />;

Component = styled.div({});
mount = <Component innerRef={(element: HTMLDivElement) => {}} />;

Component = Component.withComponent('input');
mount = <Component innerRef={(element: HTMLInputElement) => {}} />;
12 changes: 8 additions & 4 deletions packages/react-emotion/typings/react-emotion.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ export type ThemedProps<Props, Theme> = Props & {
theme: Theme,
}

type ElementProps<Tag extends keyof JSX.IntrinsicElements> =
& JSX.IntrinsicElements[Tag]
& { innerRef?: JSX.IntrinsicElements[Tag]['ref'] }

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

withComponent(component: Component<Props>):
StyledComponent<Props, Theme, {}>
Expand Down Expand Up @@ -74,15 +78,15 @@ type ShorthandsFactories<Theme> = {
<Props = {}>(
strings: TemplateStringsArray,
...vars: Interpolation<ThemedProps<Props & JSX.IntrinsicElements[Tag], Theme>>[],
): StyledComponent<Props, Theme, JSX.IntrinsicElements[Tag]>
): StyledComponent<Props, Theme, ElementProps<Tag>>

// overload for object as styles
<Props = {}>(
...styles: (
| ObjectStyleAttributes
| ((props: ThemedProps<Props & JSX.IntrinsicElements[Tag], Theme>) => ObjectStyleAttributes)
)[]
): StyledComponent<Props, Theme, JSX.IntrinsicElements[Tag]>
): StyledComponent<Props, Theme, ElementProps<Tag>>
};
};

Expand All @@ -91,7 +95,7 @@ export interface ThemedReactEmotionInterface<Theme> extends ShorthandsFactories<
<Props, Tag extends keyof JSX.IntrinsicElements>(
tag: Tag,
options?: Options,
): CreateStyled<Props, Theme, JSX.IntrinsicElements[Tag]>
): CreateStyled<Props, Theme, ElementProps<Tag>>

// overload for component
<Props>(
Expand Down