2016-11-28 44 views
5

我的問題減少到這個例子:不能導入導出接口 - 出口未發現

test.model.ts

export class A { 
    a: number; 
} 

export interface B { 
    b: number; 
} 

test.component.ts

import { Component, Input } from '@angular/core'; 
import { A, B } from './test.model'; 

@Component({ 
    selector: 'test', 
    template: '<h1>test</h1>' 
}) 
export class TestComponent { 

    //This works fine 
    @Input() foo: A; 

    //Does NOT work - export 'B' was not found in './test.model' 
    @Input() bar: B; 

} 

當我想要使用接口我得到以下警告:

WARNING in ./src/app/.../test.component.ts 
21:76 export 'B' was not found in './test.model' 

但是,使用類是OK。任何提示?

UPDATE:這似乎是某種方式與這個問題有關:https://github.com/webpack/webpack/issues/2977

+0

這是不是已經在這裏得到解答? http://stackoverflow.com/questions/30270084/why-the-limitation-on-exporting-an-interface-by-default-in-typescript –

+1

我不這麼認爲 - 這個問題涉及默認出口,我不知道沒用。不管怎麼說,還是要謝謝你。 – user2878850

+1

啊對不起,沒有正確閱讀 –

回答

9

昨天,我發現了另一個問題,在這裏和解決其申報出口接口是一個單獨的文件。每個文件有一個界面,它對我沒有任何警告。

+1

這對我有效,下面是對原因的解釋:https://github.com/angular/angular-cli/issues/2034#issuecomment -302666897 – Chris

0

這爲我工作:使用

@Input() bar: B | null; 

角4.4.3 +打字稿2.3.4

+0

如果您允許'null'作爲有效的輸入值(否則它將違反類型安全性),這將起作用。 – MCattle