Flow: 0.134.0 throws signature-verification-failure with React.memo return type

Created on 19 Sep 2020  ยท  3Comments  ยท  Source: facebook/flow

Flow version: 0.134.0

Expected behavior

In [email protected] the following code worked without errors:

// @flow strict

import React, {type Element, memo} from 'react';

type PropsType = {}

export const Thing = (props: PropsType): Element<'div'> => {
    return <div />;
};

export default memo<PropsType>(Thing);

Actual behavior

However, in [email protected] this now throws this error:

Error โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ components/mycomponent.js:28:16

Cannot build a typed interface for this module. You should annotate the exports of this module with types. Cannot
determine the type of this call expression. Please provide an annotation, e.g., by adding a type cast around this
expression. [signature-verification-failure]

     25โ”‚    </div>
     26โ”‚ );
     27โ”‚
     28โ”‚ export default memo<PropsType>(Thing);
     29โ”‚

I understand that this is a result of flow enabling Types-first checking in 0.134.0 but I am surprised at this failure as React's typed are built-in and the return type of memo() should be handled by default. Am I wrong in that assumption? If so -- what is the recommended way to address this? This way of defining React component is pretty standard in the community.

What's stranger is that I can't reproduce this error on "Try-Flow" but can reproduce it consistently on several machines (and my CI server) when upgrading to 0.134.0.

bug needs triage

Most helpful comment

Yes this is a result of types first being enabled by default. If you plan to keep types first on, which you should since it's the standard, you have to type it as React.AbstractComponent.

Which can look something like this

export default (React.memo<Props>(Thing): React.AbstractComponent<Props, mixed>);

All 3 comments

Yes this is a result of types first being enabled by default. If you plan to keep types first on, which you should since it's the standard, you have to type it as React.AbstractComponent.

Which can look something like this

export default (React.memo<Props>(Thing): React.AbstractComponent<Props, mixed>);

Or you can try a bit cleaner named exports

export const Component: React.AbstractComponent<Props, mixed> = React.memo<Props>(() => {
  return null
});

That's good enough for me. A little annoying but worth the tradeoff in improved performance. Thanks for the quick answer!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

john-gold picture john-gold  ยท  3Comments

Beingbook picture Beingbook  ยท  3Comments

philikon picture philikon  ยท  3Comments

damncabbage picture damncabbage  ยท  3Comments

mjj2000 picture mjj2000  ยท  3Comments