gpt4 book ai didi

javascript - 流 JavaScript "Missing type annotation for T"和 "Missing type annotation for S"

转载 作者:行者123 更新时间:2023-12-01 01:27:31 29 4
gpt4 key购买 nike

我正在上 React Native 类(class),然后使用 Flow 尝试纠正类(class)中的错误,因为讲师没有使用任何类型检查。

我在 Flow 中遇到了另一个错误,通过在互联网上进行长时间搜索找不到答案。我在同一行收到这两个错误。我不知道这些错误的流量意味着什么。这让我很困惑,搜索 Flow 文档对我没有帮助,因为它根本没有解释这一点。

我正在使用 Atom 与 Nuclide 和 Flow 0.78。

Missing type annotation for T.

Missing type annotation for S.

这是我标记出错误的代码。

    /* @flow */
import { ADD_PLACE, DELETE_PLACE, SELECT_PLACE, DESELECT_PLACE } from '../actions/actionTypes.js'

type State = {
places: Array<Object>,
selectedPlace: ?{
key: string,
name: string,
image: Image
}};
type Action = { type : string, placeName: string, placeKey: string};

const initialState = {
places: [],
selectedPlace: null
}


const reducer = (state : State = initialState, action : Action) => {

switch (action.type) {
case ADD_PLACE:
return {
...state,
places: state.places.concat({ <-- Error
key: String(Math.random()),
name: action.placeName,
image: {
uri: "https://cdn.newsapi.com.au/image/v1/f08d8ccc83fbc2d08529aea69890ad4d?width=1024"
}
})
};
case DELETE_PLACE:
return {
...state,
places: state.places.filter(place => {. <--Error
return state.selectedPlace && place.key !== state.selectedPlace.key;
}),
selectedPlace: null
};
case SELECT_PLACE:
return {
...state,
selectedPlace: state.places.find(place => {
return place.key == action.placeKey;
})
};
case DELETE_PLACE:
return {
...state,
selectedPlace: null
};
default:
return state;
}

};

export default reducer;

这些错误令人沮丧,而且毫无意义。我确信我不是唯一一个为此苦苦挣扎的人。可能还有其他人。

如果有人知道这个问题的答案。我们将不胜感激。

此外,如果有人可以指出一些文档,将这些类型的 Flow 错误转换为更有意义或更容易理解的内容,这将是一个很大的帮助,因为官方文档没有解释太多,也没有太多示例学习借鉴。

如果有一些更明确的文档可以学习,那也会有很大帮助。

谢谢。

最佳答案

从 Flow v0.70 开始,使用 filter、map、concat 等数组方法的导出函数应指定返回类型。在你的情况下,这应该可以解决它:

const reducer = (state : State = initialState, action : Action): State

参见this详细讨论。

关于javascript - 流 JavaScript "Missing type annotation for T"和 "Missing type annotation for S",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53627425/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com