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 ClassInterpolation to typings #676

Merged
merged 1 commit into from
May 26, 2018
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
3 changes: 3 additions & 0 deletions packages/create-emotion-styled/types/react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TypeScript Version: 2.3

import React, { ComponentClass, Ref, SFC } from 'react';
import { ClassInterpolation } from 'create-emotion';

import {
Interpolation,
Expand Down Expand Up @@ -30,10 +31,12 @@ export interface StyledComponentMethods<Props extends object, InnerProps extends

export interface StyledStatelessComponent<Props extends object, InnerProps extends object, Theme extends object>
extends ComponentClass<StyledStatelessProps<Props & InnerProps, Theme>>,
ClassInterpolation,
StyledComponentMethods<Props, InnerProps, Theme> {}

export interface StyledOtherComponent<Props extends object, InnerProps extends object, Theme extends object>
extends ComponentClass<StyledOtherProps<Props & InnerProps, Theme, Ref<any>>>,
ClassInterpolation,
StyledComponentMethods<Props, InnerProps, Theme> {}

export type StyledComponent<Props extends object, InnerProps extends object, Theme extends object> =
Expand Down
14 changes: 10 additions & 4 deletions packages/create-emotion-styled/types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const StyledCompWithFunComp2 = StyledFunComp0.withComponent(TestFunComp1);

const StyledCompShorthand0 = createStyled.a({
textAlign: 'center',
})
});
const StyledCompShorthand1 = createStyled.label`
display: block;

Expand All @@ -168,13 +168,13 @@ const getEditorLogoColor = (editor: 'vscode' | 'emacs' | 'sublime') => {
case 'sublime':
return 'ff9800';
}
}
};

const StyledCompShorthandWithProps0 = createStyled.div<ShorthandProps>(props => ({
backgroundColor: getEditorLogoColor(props.editor),
}));
const StyledCompShorthandWithProps1 = createStyled.section<ShorthandProps>`
backgroundColor: ${props => getEditorLogoColor(props.editor)};
const StyledCompShorthandWithProps1 = createStyled.section`
backgroundColor: ${(props: ShorthandProps) => getEditorLogoColor(props.editor)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change?

Copy link
Member Author

@Ailrun Ailrun May 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchellhamilton Original one cannot pass checking in TS 2.3.
We should add yarn test:typescript to TravisCI...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I removed the ts tests from travis because it was crashing and I didn't have time to figure out why, if you want to fix it and add it back here that would be great.

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 I will add it after this one will be merged.

`;

<StyledCompShorthandWithProps0 editor='emacs' />;
Expand All @@ -185,3 +185,9 @@ const StyledCompShorthandWithProps1 = createStyled.section<ShorthandProps>`

// $ExpectError
createStyled.asdf;

const ComposingComp = createStyled.div`
${StyledCompShorthand0} {
color: black;
}
`;
9 changes: 9 additions & 0 deletions packages/create-emotion/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ export interface CSSObject extends CSSBaseObject, CSSPseudoObject, CSSOthersObje

export interface ArrayInterpolation extends Array<Interpolation> {}

export interface ClassInterpolation extends Function {
__emotion_real: any;
__emotion_styles: Array<Interpolation>;
__emotion_base: ClassInterpolation;
__emotion_target: string;
__emotion_forwardProp: undefined | null | ((arg: string) => boolean);
}

export type Interpolation =
| undefined | null | boolean | string | number
| TemplateStringsArray
| CSSObject
| ArrayInterpolation
| ClassInterpolation
;

export interface ArrayClassNameArg extends Array<ClassNameArg> {}
Expand Down