流量函数方差产生不同的误差

时间:2019-04-29 18:41:08

标签: flowtype

我试图回答another question about Flow,并且能够写出一个与OP所发现的内容相矛盾的示例。我想我发现了两个非常简单的示例,它们展示了Flow给出的两组错误,我认为是等效代码。我很乐意帮助您理解这是否是Flow的错误,或者我是否缺少区分这两个示例的东西。

示例1

type A_void = A => void;
type A_void_void = A_void => void;

type B_void = B => void;
type B_void_void = B_void => void;

interface A {
  method: (A_void, A_void_void) => void;
}

class B implements A {
  method: (B_void, B_void_void) => void; 
}

Try Flow

示例2

type A_void = A => void;
type A_void_void = (A => void) => void

type B_void = B => void;
type B_void_void = (B => void) => void;

interface A {
  method: (A_void, A_void_void) => void;
}

class B implements A {
  method: (B_void, B_void_void) => void; 
}

Try Flow

请注意,第一个错误仅产生一个错误-在B_void中大约为B.method-而第二个示例则产生两个错误-一个错误为B_void,另一个错误为{{ 1}}在B_void_void中。

据我了解,在B.method中使用A_voidA => void作为类型并不重要,因为它们是等效的。但是,似乎它们会产生不同的错误。我希望示例2 是正确的,因为函数具有相反的输入。 A_void_voidB_voidB_void_voidA_void更具体,因此都应该引起错误。

0 个答案:

没有答案