Skip to content

Commit ffc7c58

Browse files
XeeDAndarist
authored andcommitted
Add TS type definition for useTheme from emotion-theming (#1509)
1 parent c81c003 commit ffc7c58

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"releases": [{ "name": "emotion-theming", "type": "patch" }],
3+
"dependents": []
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add TypeScript type definition for the useTheme hook in emotion-theming

packages/emotion-theming/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export function ThemeProvider<Theme>(
1414
props: ThemeProviderProps<Theme>
1515
): React.ReactElement
1616

17+
export function useTheme<Theme>(): Theme
18+
1719
/**
1820
* @todo Add more constraint to C so that
1921
* this function only accepts components with theme props.

packages/emotion-theming/types/tests.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as emotionTheming from 'emotion-theming'
22
import * as React from 'react'
33

4-
const { ThemeProvider, withTheme } = emotionTheming
4+
const { ThemeProvider, withTheme, useTheme } = emotionTheming
55

66
interface Theme {
77
primary: string
@@ -38,6 +38,11 @@ class CompCWithDefault extends React.Component<Props> {
3838
}
3939
}
4040

41+
{
42+
const theme: Theme = useTheme<Theme>()
43+
const themeFail: Theme = useTheme<number>() // $ExpectError
44+
}
45+
4146
const ThemedSFCWithDefault = withTheme(CompSFCWithDefault)
4247
;<ThemedSFCWithDefault />
4348
;<ThemedSFCWithDefault theme={theme} />

0 commit comments

Comments
 (0)