2016-02-29 65 views
0

也許這是一個愚蠢的問題,但找不到任何東西,幫助我。在靜態方法打字稿內找不到名稱「界面」

我想TS,和我正好測試接口

interface HelloWorldTS { 
     name : string; 
    } 

這個代碼中。

class Startup { 


    public static main(): number { 
     console.log('Hello World'); 

     return 0; 
    } 
} 

Startup.main(); 

interface HelloWorldTS { 
     name : string; 
    } 

class Startup { 


    public static main(): number { 
     console.log('Hello World'); 

     TSInterface : HelloWorldTS = { name: "hello"}; 

     return 0; 
    } 


} 

Startup.main(); 

,但我做一個錯誤:無法找到名稱爲「HelloWorldTS」,在這一行TSInterface : HelloWorldTS = { name: "hello"};

我的問題是,如果有可能使用從靜態方法的接口,如果所以,我的錯誤是什麼。對不起,我的英語不好,我希望你明白我想問

回答

4

你只是缺少關鍵字來聲明一個新的變量是什麼樣

interface HelloWorldTS { 
     name : string; 
    } 

class Startup { 


    public static main(): number { 
     console.log('Hello World'); 

     let TSInterface : HelloWorldTS = { name: "hello"}; 

     return 0; 
    } 


} 
+0

哦,我投你的答案,但仍不能接受它,但接受它,非常感謝你的時間。 –