Reactjs 流动类型-高阶组件-支柱注入
我尝试使用高阶组件进行道具注入,但我无法正确地进行 为什么这不正确Reactjs 流动类型-高阶组件-支柱注入,reactjs,flowtype,Reactjs,Flowtype,我尝试使用高阶组件进行道具注入,但我无法正确地进行 为什么这不正确 /* @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: R
/* @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" />;
/*@flow*/
从“React”导入*作为React;
类型FooType={
傅:字符串,
酒吧:字符串
};
constfoo=({Foo,bar}:FooType)=>{Foo}{bar};
常量addBlah=(组件:React.ComponentType)=>
({…道具})=>;
const with blah=addBlah(Foo);
常量结果=()=>;
对,使用文档似乎返回类型应该包含一个带有可选类型void的
$Diff
下面是它的样子
/* @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" />;
/*@flow*/
从“React”导入*作为React;
类型FooType={
傅:字符串,
酒吧:字符串
};
constfoo=({Foo,bar}:FooType)=>{Foo}{bar};
常量addBlah=(组件:React.ComponentType):React.ComponentType=>
({…道具})=>;
const with blah=addBlah(Foo);
常量结果=()=>;