react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

Type annotation with flow syntax and defaulting of args is breaking React Class validator

Open robinwkurtz opened this issue 7 years ago • 5 comments

Hello,

Thanks for your library!

I ran into an issue where a option (flow annotation) argument in a handler was causing my class to not be parsed.. resulting in You have to export at least one valid React Class!. Defaulting the arg also seems to break things.

Breaks:

handleThings = (id: number, active?: boolean) => () => {
   things..
}
handleThings = (id: number, active: boolean = false) => () => {
   things..
}

Works:

handleThings = (id: number, active: boolean) => () => {
   things..
}

Thanks!

robinwkurtz avatar Jul 25 '18 22:07 robinwkurtz

Which version of react-docgen are you using?

danez avatar Jul 26 '18 08:07 danez

2.21.0 which I'm now seeing is old. I'm dealing with react-doc-generator which hasn't been updated in a little while.

I've manually upgraded to 3.0.0-rc.0 and I get the same results.

Thanks!

robinwkurtz avatar Jul 26 '18 13:07 robinwkurtz

Can you provide a complete example of the file? I tried recreating the issue but when I add any of the methods you provided to to a react class it works fine.

danez avatar Jul 27 '18 09:07 danez

Sorry for the lateness... The following is a full example that gives me the above results if a toggle the handleThings handler.

// @flow

import React from 'react';

export class TestPage extends React.PureComponent {

    // Working
    handleThings = (id: number, active: boolean) => () => console.log(`handleThings: Works! ${id}, ${active}`);
    // No Working
    // handleThings = (id: number, active?: boolean) => () => console.log(`handleThings: Works! ${id}, ${active}`);
    // handleThings = (id: number, active: boolean = false) => () => console.log(`handleThings: Works! ${id}, ${active}`);

    render() {
        return (
            <button type="button" onClick={this.handleThings(1, true)}>
                [Button]
            </button>
        );
    }
}

export default TestPage;

Thanks!

robinwkurtz avatar Jul 31 '18 18:07 robinwkurtz

Just a bump here @danez, can I provide more information?

robinwkurtz avatar Aug 23 '18 15:08 robinwkurtz