Skip to content

Flow not understanding React propTypes for ES6 classes #1770

@sophistifunk

Description

@sophistifunk

Background: I'm converting a smallish package to Flow, in order to sell it to the team as a general part of our codebase.

Running 0.24.2, using the following example:

// @flow

import React, {Component, PropTypes} from 'react';

export class TestComponent extends Component {

    // props: {
    //     message: string
    // };

    someMethod() {
        console.log(this.props.badField);
    }

    render() {
        return <div>{this.props.message}</div>;
    }

}

TestComponent.propTypes = {
    message: PropTypes.string
};

Flow tells me this code has no problems. If I uncomment the duplicate props type definition, it correctly flags badField as non-existent. Using a static propTypes = {...} does not solve the problem.

I understand that duplicating the propTypes as a Flow type will fix the problem in this limited example, but I'll never get the rest of my team on-board with Flow if they have to write out all their propTypes twice. We would also not get any error messages as the duplicate definitions diverged over time, which kind of defeats the purpose of the exercise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions