1class Person<T, U, C> {
2 name: T
3 age: U
4 hobby: C[]
5
6 constructor(name: T, age: U, hobby: C[]) {
7 this.name = name
8 this.age = age
9 this.hobby = hobby
10 }
11}
12
13const output = new Person<string, number, string>('john doe', 23, ['swimming', 'traveling', 'badminton'])
14console.log(output)
1class GenericNumber<T> {
2 zeroValue: T;
3 add: (x: T, y: T) => T;
4}
5
6let myGenericNumber = new GenericNumber<number>();
7myGenericNumber.zeroValue = 0;
8myGenericNumber.add = function(x, y) { return x + y; };
9