模块导出是否有Union类型格式...例如:
// actionTypes.js
export const CREATE_ACCOUNT = 'CREATE_ACCOUNT'
export const UPDATE_ACCOUNT = 'UPDATE_ACCOUNT'
export const DELETE_ACCOUNT = 'DELETE_ACCOUNT'
// reducer.js
import * as actionTypes from './actionTypes.js'
type Action = actionTypes
export default function( state: Object, action: Action){ ... }
答案 0 :(得分:0)
您可以使用$ Values将对象的值转换为Union类型。但请注意,将字符串分配给const仍会将该值键入string
。您需要明确键入每个变量,或使用类似$ObjMap
的内容。
一个例子可能是:
// actionTypes.js
export const CREATE_ACCOUNT: 'CREATE_ACCOUNT' = 'CREATE_ACCOUNT'
export const UPDATE_ACCOUNT: 'UPDATE_ACCOUNT' = 'UPDATE_ACCOUNT'
export const DELETE_ACCOUNT: 'DELETE_ACCOUNT' = 'DELETE_ACCOUNT'
// reducer.js
import * as actionTypes from './actionTypes.js'
type Action = $Values<typeof actionTypes>;
export default function( state: Object, action: Action){ ... }