- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 69字
- 2021-07-15 17:05:34
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.