forked from emotion-js/emotion
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed styled Flow types (emotion-js#1570)
* fix: refactor styled-base Flow types to work again * fix: improve Styled type to accept optional props type * fix: make styled package return proper types * fix: missing flow header * test: test untyped styled component * chore: fix site types * docs: comment typo
- Loading branch information
Showing
12 changed files
with
213 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@emotion/styled-base': patch | ||
'@emotion/styled': patch | ||
--- | ||
|
||
Fixed package's Flow types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ | |
|
||
[options] | ||
suppress_comment=.*\\$FlowFixMe | ||
suppress_comment=.*\\$FlowExpectError | ||
sharedmemory.hash_table_pow=21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable no-unused-vars */ | ||
// @flow | ||
import * as React from 'react' | ||
import createStyled from '../src' | ||
import type { CreateStyledComponent, StyledComponent } from '../src/utils' | ||
|
||
export const valid: CreateStyledComponent = createStyled('div') | ||
|
||
// $FlowExpectError: we can't cast a StyledComponent to string | ||
export const invalid: string = createStyled('div') | ||
|
||
const styled = createStyled('div') | ||
type Props = { color: string } | ||
// prettier-ignore | ||
const Div = styled<Props>({ color: props => props.color }) | ||
|
||
const validProp = <Div color="red" /> | ||
|
||
// $FlowExpectError: color property should be a string | ||
const invalidProp = <Div color={2} /> | ||
|
||
// $FlowExpectError: we don't expose the private StyledComponent properties | ||
const invalidPropAccess = styled().__emotion_base | ||
|
||
// We allow styled components not to specify their props types | ||
// NOTE: this is allowed only if you don't attempt to export it! | ||
const untyped: StyledComponent<empty> = styled({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @flow | ||
export const tags = [ | ||
'a', | ||
'abbr', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.