Javascript 流未捕获导入组件的类型错误

Javascript 流未捕获导入组件的类型错误,javascript,reactjs,flowtype,typechecking,Javascript,Reactjs,Flowtype,Typechecking,我有一个简单的组件ErrorBoundary,在另一个组件中使用。这两个组件都通过流进行检查(即,它们具有/*@flow*/标志)。但是,如果我滥用ErrorBoundary而没有提供正确的道具,flow就不会捕捉到错误。下面是ErrorBoundary: /* @flow */ import * as React from 'react'; type Props = { children: React.Node, ErrorComponent: React.ComponentType

我有一个简单的组件
ErrorBoundary
,在另一个组件中使用。这两个组件都通过流进行检查(即,它们具有
/*@flow*/
标志)。但是,如果我滥用
ErrorBoundary
而没有提供正确的道具,flow就不会捕捉到错误。下面是
ErrorBoundary

/* @flow */
import * as React from 'react';

type Props = {
  children: React.Node,
  ErrorComponent: React.ComponentType<any>,
};

type State = {
  hasError: boolean,
};

class ErrorBoundary extends React.Component<Props, State> {
  constructor(props: Props) {
    super(props);

    this.state = { hasError: false };
  }

  componentDidCatch(error: Error, info: string) {
    console.log(error, info); // eslint-disable-line
    this.setState({ hasError: true });
  }

  render() {
    const { ErrorComponent } = this.props;

    if (this.state.hasError) {
      return <ErrorComponent />;
    }

    return this.props.children;
  }
}

export default ErrorBoundary;
/*@flow*/
从“React”导入*作为React;
类型道具={
子节点:React.Node,
ErrorComponent:React.ComponentType,
};
类型状态={
hasError:boolean,
};
类ErrorBoundary扩展了React.Component{
建造师(道具:道具){
超级(道具);
this.state={hasError:false};
}
componentDidCatch(错误:错误,信息:字符串){
console.log(错误,信息);//eslint禁用行
this.setState({hasError:true});
}
render(){
const{ErrorComponent}=this.props;
if(this.state.hasError){
返回;
}
返回此.props.children;
}
}
导出默认错误边界;
在这里,它被滥用了:

/* @flow */
import * as React from 'react';
import ErrorBoundary from '/path/to/ErrorBoundary';

type Props = {};

class SomeComponent extends React.Component<Props> {
  render() {
    return (
      <ErrorBoundary>
        {..some markup}
      </ErrorBoundary>
    )
  }
}
/*@flow*/
从“React”导入*作为React;
从“/path/to/ErrorBoundary”导入ErrorBoundary;
类型Props={};
类SomeComponent扩展了React.Component{
render(){
返回(
{..some markup}
)
}
}
尽管我没有向
ErrorBoundary
提供必要的组件
ErrorComponent
,但当我运行flow时,它会报告“无错误!”。但是,如果我要从同一个文件中导入一个类型化函数,它就可以工作。或者,如果我试图在自己的模块文件中错误地使用
ErrorBoundary
,flow也会捕获错误


问题似乎与导入专门使用flow输入的React组件有关。有人知道我可能做错了什么吗?

问题是,我的导入是通过与ErrorBoundary位于同一目录中的中间index.js文件进行的。该index.js文件没有用
/@flow
标记。一旦我添加了它,类型检查就正常工作了