有人能告诉我这个设置有什么问题吗。我做了一个小包装
react-intl
的注入组件,所以我可以使用它作为渲染道具,但编译器正在向我抱怨。。。
interface Props {
intl: InjectedIntl;
children(props: InjectedIntl): JSX.Element;
}
class Intl extends React.Component<Props, {}> {
public render() {
return this.props.children(this.props.intl);
}
}
export default injectIntl(Intl);
然后渲染道具是这样的。。。
<Intl> // <-- compiler complaining on this line
{(intl) => (
<div>
{intl.messages.iCanHazRenderProp}
</div>
)}
</Intl>
Type '{ children: (intl: InjectedIntl) => Element; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Props, ComponentState, any>> & Readonly<...'. Type '{ children: (intl: InjectedIntl) => Element; }' is not assignable to type 'Readonly<Props>'. Property 'intl' is missing in type '{ children: (intl: InjectedIntl) => Element; }'.
编辑:injectIntl的签名
(alias) injectIntl<Props>(component: ReactIntl.ComponentConstructor<Props & ReactIntl.InjectedIntlProps>, options?: ReactIntl.InjectIntlConfig | undefined): React.ComponentClass<Props> & {
WrappedComponent: ReactIntl.ComponentConstructor<Props & ReactIntl.InjectedIntlProps>;
}
导入injectIntl