Skip to content

Commit

Permalink
Add TS type definition for useTheme from emotion-theming (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
XeeD authored and Andarist committed Sep 17, 2019
1 parent c81c003 commit ffc7c58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changeset/dirty-owls-remain/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"releases": [{ "name": "emotion-theming", "type": "patch" }],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/dirty-owls-remain/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add TypeScript type definition for the useTheme hook in emotion-theming
2 changes: 2 additions & 0 deletions packages/emotion-theming/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function ThemeProvider<Theme>(
props: ThemeProviderProps<Theme>
): React.ReactElement

export function useTheme<Theme>(): Theme

/**
* @todo Add more constraint to C so that
* this function only accepts components with theme props.
Expand Down
7 changes: 6 additions & 1 deletion packages/emotion-theming/types/tests.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as emotionTheming from 'emotion-theming'
import * as React from 'react'

const { ThemeProvider, withTheme } = emotionTheming
const { ThemeProvider, withTheme, useTheme } = emotionTheming

interface Theme {
primary: string
Expand Down Expand Up @@ -38,6 +38,11 @@ class CompCWithDefault extends React.Component<Props> {
}
}

{
const theme: Theme = useTheme<Theme>()
const themeFail: Theme = useTheme<number>() // $ExpectError
}

const ThemedSFCWithDefault = withTheme(CompSFCWithDefault)
;<ThemedSFCWithDefault />
;<ThemedSFCWithDefault theme={theme} />
Expand Down

0 comments on commit ffc7c58

Please sign in to comment.