1class Info {
2 private name: string ;
3 constructor(n:string){
4 this.name = n ;
5 };
6 describe(){
7 console.log(`Your name is ${this.name}`);
8 }
9}
10
11const a = new Info('joyous');
12a.describe();
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
1class Animal { public name: string;
2 public constructor(theName: string) { this.name = theName; }
3 public move(distanceInMeters: number) { console.log(`${this.name} moved ${distanceInMeters}m.`); }}Try