Flow: Cannot declare stateless functional component with defaultProps in libdefs

Created on 13 Jun 2019  路  2Comments  路  Source: facebook/flow

Flow version: 0.101.0

I've written a stateless functional React component similar to this:

import React from 'react';

type Props: {
    a: number,
    b: string,
};

function Component({a, b}: Props): React.Node {
    return <div>a is {a} and b is {b}</div>;
}

Component.defaultProps = {
    a: 1,
};

export default Component;

I would like to be able to write a Flow libdef for this component so that it can be imported with its default props into another package. But I can't seem to get it to work, no matter how I declare Component. Is there a way to do this?

Expected behavior

The linked Try-Flow typechecks correctly

Actual behavior

The linked Try-Flow does not recognize the existence of defaultProps on component Component.

  • Link to Try-Flow or Github repo:
    Link!
bug

Most helpful comment

This is gonna be fixed in the next release! Update your try-flow link to use the master version and you'll see the error goes away!

All 2 comments

This is gonna be fixed in the next release! Update your try-flow link to use the master version and you'll see the error goes away!

Oh perfect timing, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glenjamin picture glenjamin  路  3Comments

jamiebuilds picture jamiebuilds  路  3Comments

ctrlplusb picture ctrlplusb  路  3Comments

tp picture tp  路  3Comments

Beingbook picture Beingbook  路  3Comments