2014-01-17 70 views
0

我有兩個接口:IEventIWorkflowResizedEvent,它擴展了第一個接口。呼叫簽名在帶參數的接口中不兼容

interface IEvent { 
    add?(listener:()=> void): void; 
    remove?(listener:()=> void): void; 
    trigger?(...a: any[]): void; 
} 

interface IWorkflowResizedEvent extends IEvent { 
    add(listener:(args: WorkflowResizedEventArgs) => void): void; 
    remove(listener:(args: WorkflowResizedEventArgs) => void): void; 
    trigger(args: WorkflowResizedEventArgs): void; 
} 

interface WorkflowResizedEventArgs { 
} 

我得到一個錯誤:

Interface 'IWorkflowResizedEvent cannot extend interface 'IEvent': Types of property 'trigger' of types 'IWorkflowResizedEvent' and 'IEvent' are incompatible: Call signatures of types '(args: WorkflowResizedEventArgs) => void' and '(...a: any()) => void' are incompatible: Call signature expects 0 or fewer parameters.

我用之前的一些舊版本TypeScript庫和這段代碼運行良好......現在我已經更新了庫到最新的一個並開始出現問題。我發現整個語言規範已經改變如此強烈...

有沒有人有任何想法這裏有什麼問題?它看起來應該沒問題。

回答

1

打字稿...(所謂傳播運營商)代表,我們從C#作爲params知道的東西。
根據新標準,您將在方法調用/覆蓋中使用spread運算符。這就是爲什麼IWorkflowResizedEvent不能延伸IEvent

試試這個:

interface IEvent { 
    add?(listener:()=> void): void; 
    remove?(listener:()=> void): void; 
    trigger?(...a: any[]): void; 
} 

interface IWorkflowResizedEvent extends IEvent { 
    add(listener:(args: WorkflowResizedEventArgs) => void): void; 
    remove(listener:(args: WorkflowResizedEventArgs) => void): void; 
    trigger(...args: WorkflowResizedEventArgs[]): void; 
} 

interface WorkflowResizedEventArgs { 
} 
+0

謝謝M8!你是個紳士! – Nickon

相關問題