Flow: allow intersection types for `styled()`
See original GitHub issueVersion
styled-components: 2.2.3
flow-typed: styled-components_v2.x.x.js
Reproduction
Sometimes, it’s useful to attach a component onto another component as a namespacing technique.
In flow, this can be done by typing your base component as an intersection. It looks something like:
/* @flow */
import type { ComponentType } from 'react'
import React from 'react'
import styled from 'styled-components'
type SubHeaderProps = {
textTransform: string,
}
const SubHeader: ComponentType<SubHeaderProps> = styled.h2`
textTransform: ${({ textTransform }) => textTransform};
`
type HeaderProps = {
color: string,
}
type HeaderType = {
SubHeader: ComponentType<SubHeaderProps>,
}
const Header: ComponentType<HeaderProps> & HeaderType = styled.h1`
color: ${({ color }) => color};
`
// Attach SubHeader on Header
Header.SubHeader = SubHeader
/**************************
* Using `styled() *
**************************/
const StyledHeader = styled(Header) // Unexpected -- causes flow error: styled() does not allow intersection types
Expected Behavior
Ideally styled()
wouldn’t cause a Flow error here 😃.
Actual Behavior
call of styled. Function cannot be called on any member of intersection type
is thrown by flow.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Intersection Types | Flow
Intersection types are the opposite of union types. When calling a function that accepts an intersection type, we must pass in all of...
Read more >eslint-plugin-flowtype - npm
This plugin exports a recommended configuration that enforces Flow type good ... Enforces a particular array type annotation style of simple types.
Read more >API Reference - styled-components
This is a method that creates a new StyledComponent with a different tag or component applied to it, but all the same rules...
Read more >Documentation - Conditional Types - TypeScript
Create types which act like if statements in the type system.
Read more >eslint-plugin-flowtype | Yarn - Package Manager
NPM version Travis build status js-canonical-style · Flow type linting rules for ESLint. eslint-plugin-flowtype. Installation; Configuration.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
still not fixed, huh?
@sohkai I’d recommend moving this issue to https://github.com/flowtype/flow-typed since that’s where the types are