【发布时间】:2014-10-30 11:48:12
【问题描述】:
我想构建一个函数,它接受任何对象并返回该对象并添加少量属性。比如:
//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()
对于上面的代码typescript编译器返回一个接口只能添加一个类或者接口的错误,我该如何在typescript中表达呢。
【问题讨论】:
标签: typescript