2
对于RemoteEntity
每一个实例不兼容的,我得到的类型参数This type is incompatible with empty
一个错误,在newRemoteEntity
引用为value
的null
值:也许型泛型类型参数是空
export type RemoteEntity<T: Identifiable> = {
value: ?T;
error: ?Error;
// ...
}
export function newRemoteEntity(): RemoteEntity<*> {
return {
value: null, // error
error: null, // OK
// ...
}
}
如果我不是声明value: ?Object
,这些错误消失(但随后我得到与我的类型绑定的损失有关的其他错误)。我错过了什么,或者是这种FlowType错误/怪癖吗?
什么是“可识别”类型? T需要是“可识别的”,但newRemoteEntity将其转换为空值。我想这是错误的根源。你能链接到flowtype.org/try的例子吗? – thejohnbackes
我刚刚贴上了这个例子,并且定义了我自己的'Identifiable'类型并且没有错误。这个问题有一些缺失。 –
我永远无法获得'flowtype.org/try'工作;在多个浏览器中只有三个涟漪点。 'Identifiable'只是'Type Identifiable = {id:string}'。 –