[英]Flowtype not detecting type of property inside object
我遇到以下錯誤
90: var b = action.data;
^^^^ property `data`. Property not found in
90: var b = action.data;
^^^^^^ object type
這在一個函數內部,該函數接收action
作為這樣的參數:
export default (state: SecurityGroupState = { groups: null, editingIPRange: null }, action: Action) => {
使用import type
Action
import type
如下所示:
import type { Action } from "../../actions";
它被聲明為:
export type Action = {
type: string,
data: Object,
} | {
type: string,
error: Object,
};
觸發初始錯誤的代碼如下:
switch (action.type) {
case GET:
if (action.error) {
console.error(action.error);
break;
}
var a = action.data; // no error here
const groupsCopy2 = _.map(state.groups, () => {
var b = action.data;
});
}
因此,在var a = ...
行中,Flow可以使用action.data
,但是在lambda map
內部似乎不知道該action: Action
可以具有data
鍵。
Flow對改進不抱樂觀態度,它認為每個函數調用都可以修改action.data
。 至於修復,您可以使用const
綁定
const data = action.data
const groupsCopy2 = _.map(state.groups, () => {
var b = data;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.