我正在为我的观看容器编写redux操作时尝试关注piotrwitek's redux-typescript-guide.。
出于某种原因,它会停止,因为找不到setCarRegNr
,即使它已导入。
知道为什么会失败吗?
import * as React from "react"
import { setCarRegNr } from "../actions/status"
type Actions = setCarRegNr
// ^ Cannot find name 'setCarRegNr'
的src /动作/ status.ts
import { createAction } from "typesafe-actions"
import * as actionTypes from "../action-types/status"
export const setCarRegNr = createAction(actionTypes.SET_CAR_REG_NR,
(carRegNr: string) => ({
type: actionTypes.SET_CAR_REG_NR,
payload: {
carRegNr
},
})
)
答案 0 :(得分:0)
您不能使用常量作为类型,您可以使用typeof
获取常量类型:
type Actions = typeof setCarRegNr