-
-
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
Fix typing for create-emotion-styled #671
Merged
emmatown
merged 5 commits into
emotion-js:master
from
Ailrun:typing/create-emotion-styled
May 25, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c3e0521
Divide typings into two files
Ailrun ecec757
Fix types to make exposed type simpler and clearer
Ailrun b05cb98
Add testcases and fix typing for it
Ailrun 1915489
Add shorthand typing for create-emotion-styled
Ailrun 09eb62f
Update package.json
emmatown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun> | ||
// TypeScript Version: 2.3 | ||
|
||
import { Emotion, Interpolation as BaseInterpolation } from 'create-emotion'; | ||
|
||
export interface ArrayInterpolation<Props> extends Array<Interpolation<Props>> {} | ||
export type FunctionInterpolation<Props> = (props: Props, context: any) => Interpolation<Props>; | ||
|
||
export type Interpolation<Props> = | ||
| BaseInterpolation | ||
| ArrayInterpolation<Props> | ||
| FunctionInterpolation<Props> | ||
; | ||
|
||
export interface StyledOptions { | ||
e?: string; | ||
label?: string; | ||
target?: string; | ||
shouldForwardProp?: (name: string) => boolean; | ||
} | ||
|
||
export type Themed<P extends object, T extends object> = P & { theme: T }; | ||
|
||
export type StyledStatelessProps<P extends object, T extends object> = | ||
& P | ||
& { theme?: T } | ||
; | ||
export type StyledOtherProps<P extends object, T extends object, R> = | ||
& StyledStatelessProps<P, T> | ||
& { innerRef?: R } | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun> | ||
// TypeScript Version: 2.3 | ||
|
||
import React, { ComponentClass, Ref, SFC } from 'react'; | ||
|
||
import { | ||
Interpolation, | ||
StyledOptions, | ||
StyledOtherProps, | ||
StyledStatelessProps, | ||
Themed, | ||
} from './common'; | ||
|
||
export interface StyledComponentMethods<Props extends object, InnerProps extends object, Theme extends object> { | ||
withComponent<T extends keyof JSX.IntrinsicElements>( | ||
tag: T, | ||
options?: StyledOptions, | ||
): StyledOtherComponent<Props, JSX.IntrinsicElements[T], Theme>; | ||
|
||
withComponent<IP extends object>( | ||
component: SFC<IP>, | ||
options?: StyledOptions, | ||
): StyledStatelessComponent<Props, IP, Theme>; | ||
|
||
withComponent<IP extends object>( | ||
component: ComponentClass<IP>, | ||
options?: StyledOptions, | ||
): StyledOtherComponent<Props, IP, Theme>; | ||
} | ||
|
||
export interface StyledStatelessComponent<Props extends object, InnerProps extends object, Theme extends object> | ||
extends ComponentClass<StyledStatelessProps<Props & InnerProps, Theme>>, | ||
StyledComponentMethods<Props, InnerProps, Theme> {} | ||
|
||
export interface StyledOtherComponent<Props extends object, InnerProps extends object, Theme extends object> | ||
extends ComponentClass<StyledOtherProps<Props & InnerProps, Theme, Ref<any>>>, | ||
StyledComponentMethods<Props, InnerProps, Theme> {} | ||
|
||
export type StyledComponent<Props extends object, InnerProps extends object, Theme extends object> = | ||
| StyledStatelessComponent<Props, InnerProps, Theme> | ||
| StyledOtherComponent<Props, InnerProps, Theme> | ||
; | ||
|
||
export interface CreateStyledStatelessComponent<InnerProps extends object, Theme extends object> { | ||
<Props extends object, OverridedTheme extends object = Theme>( | ||
...args: Array<Interpolation<Themed<Props, OverridedTheme>>> | ||
): StyledStatelessComponent<Props, InnerProps, OverridedTheme>; | ||
} | ||
|
||
export interface CreateStyledOtherComponent<InnerProps extends object, Theme extends object> { | ||
<Props extends object, OverridedTheme extends object = Theme>( | ||
...args: Array<Interpolation<Themed<Props, OverridedTheme>>> | ||
): StyledOtherComponent<Props, InnerProps, OverridedTheme>; | ||
} | ||
|
||
export interface CreateStyledFunction<Theme extends object> { | ||
<T extends keyof JSX.IntrinsicElements>( | ||
tag: T, | ||
options?: StyledOptions, | ||
): CreateStyledOtherComponent<JSX.IntrinsicElements[T], Theme>; | ||
|
||
<IP extends object>( | ||
component: SFC<IP>, | ||
options?: StyledOptions, | ||
): CreateStyledStatelessComponent<IP, Theme>; | ||
|
||
<IP extends object>( | ||
component: ComponentClass<IP>, | ||
options?: StyledOptions, | ||
): CreateStyledOtherComponent<IP, Theme>; | ||
} | ||
|
||
export type CreateStyledShorthands<Theme extends object> = { | ||
[T in keyof JSX.IntrinsicElements]: CreateStyledOtherComponent<JSX.IntrinsicElements[T], Theme>; | ||
}; | ||
|
||
export interface CreateStyled<Theme extends object = any> | ||
extends CreateStyledFunction<Theme>, | ||
CreateStyledShorthands<Theme> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a reason this needs
Theme extends object = any
whereas the shorthand one doesn't need= any
?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
CreateStyled
is access point of all API, whereCreateStyledShorthands
is just a base interface (well, it's not really interface, but in some way, it's similar to interface) ofCreateStyled
.Therefore,
CreateStyled
is one used by user, so I put the default type on this interface only.