Skip to content

Commit

Permalink
fix: make styled package return proper types
Browse files Browse the repository at this point in the history
  • Loading branch information
FezVrasta committed Oct 26, 2019
1 parent ee69409 commit f8d31ba
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/styled-base/src/index.js
Expand Up @@ -77,6 +77,7 @@ let createStyled: CreateStyled = (tag: any, options?: StyledOptions) => {
}
}

// $FlowFixMe: we need to cast StatelessFunctionalComponent to our PrivateStyledComponent class
const Styled: PrivateStyledComponent<P> = withEmotionCache(
(props, context, ref) => {
return (
Expand Down Expand Up @@ -201,7 +202,7 @@ let createStyled: CreateStyled = (tag: any, options?: StyledOptions) => {
) {
return 'NO_COMPONENT_SELECTOR'
}
// $FlowFixMe
// $FlowFixMe: coherce undefined to string
return `.${targetClassName}`
}
})
Expand Down
3 changes: 2 additions & 1 deletion packages/styled-base/src/utils.js
Expand Up @@ -46,5 +46,6 @@ export type CreateStyledComponent = <P>(

export type CreateStyled = {
(tag: React.ElementType, options?: StyledOptions): CreateStyledComponent,
[key: string]: CreateStyledComponent
[key: string]: CreateStyledComponent,
bind: () => CreateStyled
}
6 changes: 6 additions & 0 deletions packages/styled/flow-tests/flow.js
@@ -0,0 +1,6 @@
// @flow
import styled from '../src'

export const Foo = styled.div<{}>({
color: 'red'
})
2 changes: 1 addition & 1 deletion packages/styled/src/index.js
Expand Up @@ -5,7 +5,7 @@ import { tags } from './tags'
// bind it to avoid mutating the original function
const newStyled = styled.bind()

tags.forEach(tagName => {
tags.forEach((tagName: string) => {
newStyled[tagName] = newStyled(tagName)
})

Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Title.js
Expand Up @@ -3,7 +3,7 @@ import styled from '@emotion/styled'
import { constants, mq, colors } from '../utils/style'
import * as markdownComponents from '../utils/markdown-styles'

export default styled(markdownComponents.h1)(
export default styled(markdownComponents.h1)<{}>(
mq({
paddingTop: 0,
marginTop: 0,
Expand Down

0 comments on commit f8d31ba

Please sign in to comment.