Skip to content

Commit 8c732a5

Browse files
Andaristemmatown
authored andcommitted
Allow for parametrizing styled calls with Theme type (#1398)
1 parent c673e20 commit 8c732a5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/styled-base/types/index.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,23 @@ type ReactClassPropKeys = keyof React.ClassAttributes<any>
5656
export interface CreateStyledComponentBase<
5757
InnerProps,
5858
ExtraProps,
59-
Theme extends object
59+
StyledInstanceTheme extends object
6060
> {
6161
<
6262
StyleProps extends Omit<
6363
Overwrapped<InnerProps, StyleProps>,
6464
ReactClassPropKeys
65-
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>
65+
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>,
66+
Theme extends object = StyledInstanceTheme
6667
>(
6768
...styles: Array<Interpolation<WithTheme<StyleProps, Theme>>>
6869
): StyledComponent<InnerProps, StyleProps, Theme>
6970
<
7071
StyleProps extends Omit<
7172
Overwrapped<InnerProps, StyleProps>,
7273
ReactClassPropKeys
73-
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>
74+
> = Omit<InnerProps & ExtraProps, ReactClassPropKeys>,
75+
Theme extends object = StyledInstanceTheme
7476
>(
7577
template: TemplateStringsArray,
7678
...styles: Array<Interpolation<WithTheme<StyleProps, Theme>>>

packages/styled/types/tests.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ styled.body
88
styled.div
99
// $ExpectType CreateStyledComponentIntrinsic<"svg", {}, any>
1010
styled.svg
11+
12+
{
13+
// $ExpectType CreateStyledComponentIntrinsic<"svg", { bar: string }, { themed: "black" }>
14+
styled.div<{ bar: string }, { themed: 'black' }>`
15+
color: ${props => {
16+
// $ExpectType { themed: "black" }
17+
const { theme } = props
18+
return theme.themed
19+
}};
20+
`
21+
}

0 commit comments

Comments
 (0)