Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor styled-base Flow types to work again #1570

Merged
merged 8 commits into from Oct 27, 2019
Merged
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
FezVrasta marked this conversation as resolved.
Show resolved Hide resolved
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
}
13 changes: 13 additions & 0 deletions packages/styled/flow-tests/flow.js
@@ -0,0 +1,13 @@
// @flow
import * as React from 'react'
import styled from '../src'

type Props = { color: string }
const Foo = styled.div<Props>({
color: 'red'
})

export const valid = <Foo color="red" />

// $FlowExpectError: color must be string
export const invalid = <Foo color={2} />
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) => {
FezVrasta marked this conversation as resolved.
Show resolved Hide resolved
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