【问题标题】:HOC: type parameter `Props` of function call. Missing annotationHOC:函数调用的类型参数`Props`。缺少注释
【发布时间】:2017-10-11 06:10:16
【问题描述】:
type ButtonProps = {
  children: React.Node,
  href: string,
  onClick: Function,
};

const Button = (props: ButtonProps) => (
  <a href={props.href} onClick={props.onClick}>
    <button type="submit">
      <span>{props.children}</span>
    </button>
  </a>
);

function hoc<Props: {}>(
  Component: React.ComponentType<Props>,
): React.ComponentType<Props> {
  return function WrapperComponent(props: Props) {
    return <Component {...props} />;
  };
}

export default hoc(Button);

我想要实现的是一个通用的高阶组件,它可以包装任何类组件以及无状态功能组件。上面的简化实现几乎取自https://flow.org/en/docs/react/hoc/

这给了我以下错误,我不完全理解,因为我的印象是我正在遵循文档中提供的示例:

type parameter `Props` of function call. Missing annotation

Reproducible example on try

【问题讨论】:

    标签: javascript reactjs flowtype


    【解决方案1】:

    看起来其他人也报告了这个错误:https://github.com/facebook/flow/issues/4905

    似乎最近才修复(v0.55):https://github.com/facebook/flow/issues/4709#issuecomment-334555165

    【讨论】:

    • 没有进行道具插入,所以我不确定$Diff 在这种特殊情况下会有什么帮助。
    • @Eelke 该部分与您的问题无关,如果您查看我的第二个链接上的 OP,则示例案例几乎完全是您的。似乎存在导出 HOC 样式类型的错误
    • 在我的情况下似乎没有修复,因为上面的 flow.try 链接在 0.56 版本上并且仍然错误
    猜你喜欢
    • 2018-03-24
    • 2019-07-05
    • 2019-06-21
    • 1970-01-01
    • 2023-03-09
    • 2019-05-06
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多