【发布时间】:2018-04-14 01:40:55
【问题描述】:
假设我有这个通用流类型:
/* @flow */
type Cat<T> = {
get:()=>T
};
我想创建一个创建猫的函数:
const makeCat:<U>(getter:()=>U)=>Cat<U>
= (getter) => ({get:getter});
Flow 给我以下错误:
Cannot assign function to `makeCat` because `U` [1] is incompatible with `U` [2] in the return value of property `get` of the return value.
我尝试了几种不同的方法来定义传入的“getter”的类型,但总是同样的错误。
【问题讨论】:
-
I managed to get a working example after making the code look more readable. 无法解释为什么这行得通,但你的行不通。也许对类型系统有更了解的人可以
-
谢谢你,这行得通!如果您作为答案发布,我会接受。
-
我通常不会在没有适当解释的情况下发布答案,但可以肯定!
标签: javascript flowtype