Skip to content

Commit

Permalink
Fix the type of props.theme for StyledComponent without AdditionalP…
Browse files Browse the repository at this point in the history
…rops (#1708)

* Fix Theme type

* Add unit test for theme type

* Extract the Theme test in a separate test

* Add changeset

* Better changeset

Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
fabien0102 and Andarist committed Jan 9, 2020
1 parent 31e610f commit b79781f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tasty-goats-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/styled': patch
---

Fix `props.theme` type in styled component interpolation being optional (`Theme | undefined`) for components without `AdditionalProps` being specified.
4 changes: 3 additions & 1 deletion packages/styled/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export interface CreateStyledComponent<

(
template: TemplateStringsArray,
...styles: Array<Interpolation<ComponentProps & SpecificComponentProps>>
...styles: Array<
Interpolation<ComponentProps & SpecificComponentProps & { theme: Theme }>
>
): StyledComponent<ComponentProps, SpecificComponentProps>

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/styled/types/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const Input4 = styled.input<AdditionalTest>`
marginLeft: props.left
})}
`
const Input5 = styled.input`
color: ${props => props.theme.primary};
`
;<Input
onChange={(evt: React.ChangeEvent<HTMLInputElement>) =>
console.log(evt.target.value)
Expand Down

0 comments on commit b79781f

Please sign in to comment.