我已經定義像這樣的模塊中target.d.ts
打字稿模塊未發現
declare module "target" {
export interface Group {
name: string;
targets?: Target[];
}
export interface Target {
device: Device;
property: Property;
value?: Value;
}
export interface Value {
value: number;
id?: number;
timestamp?: number;
}
export interface Property {
id: number;
name: string;
channel: number;
type: string;
}
export interface Device {
id: number;
name: string;
type: string;
}
}
現在我使用定義的接口組件中的像
import {Component, OnInit} from '@angular/core';
import {BackendUrl} from '../../../../common/settings';
import {contentHeaders} from "../../../../common/headers";
import {EventService} from "../../../../service/event.service";
import {Input} from "@angular/core/src/metadata/directives";
import {Message} from "stompjs";
import {Target} from "target";
@Component({
selector: 'device-switch',
templateUrl: './switch.component.html'
})
export class SwitchComponent implements OnInit {
@Input()
public title: string;
@Input()
public device: any;
@Input()
public property: any;
private checked: boolean;
constructor(public authHttp: AuthHttp, private eventService: EventService) {
this.checked = false;
}
ngOnInit() {
this.eventService.messages.subscribe(this.on_next);
}
/** Consume a message from the eventService */
public on_next = (message: Message) => {
let data : Target = JSON.parse(message.body);
if(data.device.id === this.device.id && data.property.name === this.property.name) {
this.checked = (data.value.value > 0);
}
};
}
的問題是,所述@Input()
變量device
和property
也是我的target
模塊中定義的接口類型。
但如果我import {Target, Device, Property} from "target";
編譯器會引發錯誤
ERROR in ./src/app/component/view/part/device/switch.component.ts
Module not found: Error: Can't resolve 'target' in '~/git/xx/frontend/src/app/component/view/part/device'
@ ./src/app/component/view/part/device/switch.component.ts 16:0-28
@ ./src/app/component/view/part/group.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi main
我不知道什麼問題...的IntelliJ並不突出什麼...似乎是確定。