通用擴展接口我想建立一個功能女巫採取任何對象,並返回該對象很少添加的屬性。是這樣的:在打字稿
//this code doesn't work
function addProperties<T>(object: T): IPropertiesToAdd<T> {/*implmentions code*/};
interface IPropertiesToAdd<T> extend T{
on(): void;
off(): void;
}
//usage example
var str = new String('Hello')
addProperties(str)
str.charAt(3)
str.on()
上面的代碼編譯打字稿返回錯誤的接口只能添加一個類或接口,我怎麼能在打字稿表達這一點。
感謝您的時間,在架構變化不大,你的答案真的幫助。 – user2692945 2014-10-30 14:26:30