Skip to content

Commit

Permalink
Allow for parametrizing styled calls with Theme type (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored and emmatown committed Jun 20, 2019
1 parent c673e20 commit 8c732a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/styled-base/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,23 @@ type ReactClassPropKeys = keyof React.ClassAttributes<any>
export interface CreateStyledComponentBase<
InnerProps,
ExtraProps,
Theme extends object
StyledInstanceTheme extends object
> {
<
StyleProps extends Omit<
Overwrapped<InnerProps, StyleProps>,
ReactClassPropKeys
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>,
Theme extends object = StyledInstanceTheme
>(
...styles: Array<Interpolation<WithTheme<StyleProps, Theme>>>
): StyledComponent<InnerProps, StyleProps, Theme>
<
StyleProps extends Omit<
Overwrapped<InnerProps, StyleProps>,
ReactClassPropKeys
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>,
Theme extends object = StyledInstanceTheme
>(
template: TemplateStringsArray,
...styles: Array<Interpolation<WithTheme<StyleProps, Theme>>>
Expand Down
11 changes: 11 additions & 0 deletions packages/styled/types/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ styled.body
styled.div
// $ExpectType CreateStyledComponentIntrinsic<"svg", {}, any>
styled.svg

{
// $ExpectType CreateStyledComponentIntrinsic<"svg", { bar: string }, { themed: "black" }>
styled.div<{ bar: string }, { themed: 'black' }>`
color: ${props => {
// $ExpectType { themed: "black" }
const { theme } = props
return theme.themed
}};
`
}

0 comments on commit 8c732a5

Please sign in to comment.