question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flow: allow intersection types for `styled()`

See original GitHub issue

Version

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:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
SilencerWebcommented, Jan 21, 2018

still not fixed, huh?

2reactions
probablyupcommented, Jun 21, 2018

@sohkai I’d recommend moving this issue to https://github.com/flowtype/flow-typed since that’s where the types are

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found