我在使用Mobx的create-react-app环境中使用流类型检查 . 我不想弹出 . 我不使用属性,也不想这样做 .

在observer()中包装组件会产生工作代码 . 类验证,并对组件进行类型检查传递 . 但是,没有对Component.props进行类型检查,因为观察者包装器太模糊了 .

这个简单的测试组件有效:

type Props = {|
    whoall: string
|};

class TestType extends React.Component<Props> {
    render() {
        return (
            <div>Hello, {this.props.whoall}!</div>
        );
    }
};

export default observer(TestType);

[...]

<TestType greeting="world" />

问题是它流动也悄然允许这样:

<TestType />

这是无效的 .

我已经尝试显式地转换返回类型,但是(我真的不明白这一点),即使TestType扩展了Component,flow告诉我它不是 .

class TestType extends React.Component<Props> {
    [...]
};

const Test : TestType = observer(TestType);
export default Test; // <-- Definitely TestType

令人惊讶地给出了错误 Cannot create Test element because TestType [1] is not a React component. 但是......它扩展了Component,怎么可能不是?困惑 .

所有这些都导致了工作代码 .

有没有办法做到这导致类型检查?