2016-11-01 2 views
0

내가이 내가타이프 라이터 모듈하지

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); 
     } 

    }; 

} 

문제와 같은 구성 요소에 정의 된 인터페이스를 사용하고 지금 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; 
    } 

} 

이 같은 모듈을 정의 발견 그 @Input() 변수 deviceproperty은 내 target 모듈에도 정의 된 인터페이스 유형입니다.

하지만 import {Target, Device, Property} from "target"; 경우 컴파일러가 문제가 ... IntelliJ에 아무것도 강조하지 않습니다 무슨

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 

내가 모르는 오류가 발생합니다 ... 괜찮을 것 같다.

답변

0

오류의 가장 큰 원인은 정의 파일이 컴파일 컨텍스트에 포함되지 않아서 declare module 'target'이 호출되지 않는다는 것입니다.

당신이 그것을 포함하도록 선택할 수있는 몇 가지 방법이 있습니다

  1. 이 switch.component.ts의 상단에 ///<reference path="path/to/your/target.d.ts" />를 추가합니다.

  2. 는에 "file":[] 배열에 path/to/your/target.d.ts를 추가하여 tsconfig.json

  3. 당신의 tsconfig.json"include":[] 배열에 path/to/your/target.d.ts (또는 일치하는 것입니다 동등한 파일 패턴)를 추가합니다.

당신이 당신의 편집 컨텍스트에 포함 된 target.d.ts 다음 어디서든 응용 프로그램에서 import {Target, Device, Property} from 'target' 할 수 있어야 일단.