我在src/types
中声明了我的流类型,并将目录添加到libs下的.flowconfig
。但是,下面提供的示例不起作用!
declare type MyCustomAction = {|
type: "MY_CUSTOM_ACTION",
payload: string
|}
declare type MyCustomAction2 = {|
type: "MY_CUSTOM_ACTION",
payload: string
|}
declare type CustomAction = MyCustomAction2 | MyCustomAction
然后像这样的动作创建者:
const MyCustomActionCreator = (): Function => (dispatch: Dispatch<MyCustomAction>, getState: FlockGetState): void => {
dispatch({
type: MY_CUSTOM_ACTION,
payload: {
name: 12
}
})
}
和这样的减速器:
export const INITIAL_STATE: reducerState = Object.freeze({})
export default (state: reducerState = INITIAL_STATE, action: CustomAction): reducerState => {
switch (action.type) {
case MY_CUSTOM_ACTION:
return {
...state,
name: Object.freeze({ ...INITIAL_STATE, loading: action.payload.data.name })
}
}
}
1)在动作创建者中调度的动作不符合我的类型 2)reducer正在访问两个都不存在的字段
我希望我声明的类型存在,因为我已将它们添加到目录中:
src/types
,
此外,如果我从类型声明中完全删除其中一个声明的类型,则流仍会传递,而不会抱怨该类型不存在!我唯一的结论是,这些类型在某种程度上被全局声明为any
。任何想法都会受到欢迎!