flow-typed / flow-typed

A central repository for Flow library definitions
https://flow-typed.github.io/flow-typed/
MIT License
3.77k stars 1.33k forks source link

styled-components v5: flow types themselves fail flow lint #3813

Open walkerdb opened 4 years ago

walkerdb commented 4 years ago

Do you want to request a feature or report a bug? Bug in styled-components v5 flow types.

What is the current behavior? Latest styled-components flow types produce a flow error.

To reproduce, just install latest flow, pull down the latest styled-components flow types, and run flow.

This error will result:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ flow-typed/npm/styled-components_v5.x.x.js:416:39

Missing type annotation for V. V is a type parameter declared in function type [1] and was implicitly instantiated at
$ObjMap [2].

     413│     ElementName
     414│   >;
     415│
 [2] 416│   declare type ConvenientShorthands = $ObjMap<
     417│     BuiltinElementInstances,
 [1] 418│     <V>(V) => StyledShorthandFactory<V>
     419│   >;
     420│
     421│   declare interface Styled {
     422│     <Comp: React$ComponentType<P>, Theme, OwnProps = React$ElementConfig<Comp>>(

What is the expected behavior? Flow type should be valid

Local Environment Information Flow v. 0.123.0 (also reproduces on at least 0.122.0, haven't tried on others), latest styled-components v5 flow types.

walkerdb commented 4 years ago

cc @omninonsense

omninonsense commented 4 years ago

Hi @walkerdb!

I'm aware of this issue, but I'm not sure how to fix it. I'm not even sure if it's a bug with the libdef or a bug in Flow.

But, generally, it happens when people forget to call one of the shorthands, e.g:

// Error
const C = styled.div

vs

// Fine
const C = styled.div``

Someone made a stripped down version of the libdef that reproduces the error and they've opened an issue Flow (facebook/flow#8344)

gwing33 commented 4 years ago

I'm upgrading from an old flow version (v0.79.1), it took me a while to figure out what was going on. Found out this is causing me issues:

// $FlowFixMe[missing-annot] Upgrade Flow to v0.129.0.
export const MyDiv = styled.div``;

It correctly suppresses the error in the file but bubbles it up to the styled-components libdef. This doesn't seem like a libdef issue, but rather a flow issue.