如果我要在导出的组件中使用一个组件,Flow需要我对它进行注释,但只有当未注释的组件被呈现为导出组件的根时,才会发生这种情况。
// @flow
import React from 'react';
const ContainerA = props => <div {...props} />;
// This one throws "Missing type annotation for `props`."
const ContainerB = props => <div {...props} />;
type Props = { children: React$Node };
// No type error
export const Ok = (props: Props) => <><ContainerA>{props.children}</ContainerA></>;
// Type error (see ContainerB comment)
export const Ko = (props: Props) => <ContainerB>{props.children}</ContainerB>;如果我用其他东西(片段、div等)包装未注释的组件,则Flow不需要我对其进行注释。
我知道Flow希望我们对导出的函数、组件等进行注释。但我不是在导出该组件,而是在要导出的组件中使用它。
为什么会这样呢?
发布于 2019-10-31 18:50:28
https://stackoverflow.com/questions/58626420
复制相似问题