我尝试使用高阶分量进行道具注入,但我做对了。
请问为什么这不正确?
/* @flow */
import * as React from 'react';
type FooType = {
foo: string,
bar: string
};
const Foo = ({ foo, bar }: FooType)=> <div>{foo}{bar}</div>;
const addBlah = <T: {}>(Component: React.ComponentType<T & { bar: string }>) =>
({...props}) => <Component {...props} bar={"bar"}/>;
const WithBlah = addBlah(Foo);
const result = ()=> <WithBlah foo="foo" />;
答案 0 :(得分:1)
正确的说,与文档一起使用似乎返回类型应包含一个$Diff
以及一个可选的void类型。
这是它的样子
/* @flow */
import * as React from 'react';
type FooType = {
foo: string,
bar: string
};
const Foo = ({ foo, bar }: FooType)=> <div>{foo}{bar}</div>;
const addBlah = <T: {}>(Component: React.ComponentType<T>): React.ComponentType<$Diff<T, { bar: string | void }>> =>
({...props}) => <Component {...props} bar={"bar"}/>;
const WithBlah = addBlah(Foo);
const result = ()=> <WithBlah foo="foo" />;