我正在尝试在vueJS项目上实现接口。但是我面临着一个我无法独自解决的问题。 确实,我需要像下面这样在打字稿中获取键对象的类型(数字,字符串,对象,数组等)。
这是我的界面
export interface IFlightState {
selectedFlightInStore: string,
selectedFlightIsWatched: string,
isShowWatchList: boolean,
watchList: Array<IFlight>,
allFlightList: Array<IFlight>,
currentDetectionList: IDetection,
typeOfEvents: Array<ITypeEvent>,
currentWorkflowStatus: Array<IWorkflowStatus>,
}
export interface IWorkflowStatus {
passed: boolean,
title: string,
subtitle: string,
}
这就是我想要做的,为接口分配currentDetectionList的类型,因此将“ IWorkflowStatus”的数组分配给“ objDetectionList”变量...
objDetectionList: IFlightState['currentDetectionList']
但是TSlint抛出了以下错误
error: Parse errors in imported module './actions': Line 68: Unexpected token, expected "]"
66 | commit(UPDATE_WORKFLOW_STATUS, newState);
67 | },
> 68 | setCurrentdetectionList({ commit }: any, objDetectionList: IFlightState['currentDetectionList']) {
69 | commit(SET_CURRENT_DETECTION_LIST, objDetectionList);
70 | },
71 | toggleWatchList({ commit }: any) { (68:75) (import/no-named-as-default) at src\store\modules\flight\index.ts:2:21:
我也尝试做IFlightState.currentDetectionList
,但这不是正确的语法...请您能帮我解决这个问题吗?
先感谢
编辑: 我刚刚找到了我所需要的!这是避免tslint错误应使用的示例! :) TsPlaygroud