2014-04-11 44 views
0

這裏是代碼:類型簽名的立式功能

interface Foo 
{ 
    c : string 
} 

function foo() 
{ 
    var c = this.c 
    return c 
} 

foo.call({ c : "quux" }) 

Visual Studio中說,this : any所以this.c自動完成不起作用。如何添加一個簽名以告知this Implemented Foo因此IDE在foo內部具有用於自動完成this.的類型信息?

回答

0

由於函數foo可以與任何this上下文中使用,你需要使用一個類型斷言:

var c = (<Foo>this).c; 

否則,簽名無法推斷。