我需要在流程中将混合类型转换为形状数组。 Tryflow link
type aShapedArray = Array<{a:string}>;
//externally defined type
const transform = ():mixed => [{a: 'hello'}];
const b = transform();
if (Array.isArray(b)) {
const a: aShapedArray = b;
}
错误是
9: const a: aShapedArray = b;
^ array. Has some incompatible type argument with
9: const a: aShapedArray = b;
^ aShapedArray
Type argument `T` is incompatible:
7: const b = transform();
^ mixed. This type is incompatible with
2: type aShapedArray = Array<{a:string}>;
^ object type
答案 0 :(得分:0)
可悲的是,我找到的唯一答案是向数组添加any
强制转换。这几乎相当于flow: ignore this line
。
/* @flow */
type aShapedArray = Array<{a:string}>;
//externally defined type
const transform = ():mixed => [{a: 'hello'}];
const b: any = transform();
if (Array.isArray(b)) {
const a: aShapedArray = b;
}
尝试流程:link