2016-02-29 68 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

哦,我投你的答案,但仍不能接受它,但接受它,非常感谢你的时间。 –