
上QQ阅读APP看书,第一时间看更新
Generic interfaces
We can also define generic interfaces using the T type variable, as follows:
interface GenericFunc<T> { (arg: T): T; } function func<T>(arg: T): T { return arg; } var myFunc: GenericFunc<number> = func;
Here, we defined a generic interface and the myFunc variable of the GenericFunc type, passing the number data type for the T type variable. Then, this variable is assigned with a function named func.