1interface IEmployee {
2 empCode: number;
3 empName: string;
4 getSalary: (number) => number; // arrow function
5 getManagerName(number): string;
6}
7
1interface Task{
2 name: String; //property
3 run(arg: any):void; //method
4}
5
6class MyTask implements Task{
7 name: String;
8 constructor(name: String) {
9 this.name = name;
10 }
11 run(arg: any): void {
12 console.log(`running: ${this.name}, arg: ${arg}`);
13 }
14}
15
16let myTask: Task = new MyTask('someTask');
17myTask.run("test");
1class Animal {
2 name: string;
3 constructor(theName: string) { this.name = theName; }
4 move(distanceInMeters: number = 0) {
5 console.log(`${this.name} moved ${distanceInMeters}m.`);
6 }
7}
8
9class Snake extends Animal {
10 constructor(name: string) { super(name); }
11 move(distanceInMeters = 5) {
12 console.log("Slithering...");
13 super.move(distanceInMeters);
14 }
15}
16
17class Horse extends Animal {
18 constructor(name: string) { super(name); }
19 move(distanceInMeters = 45) {
20 console.log("Galloping...");
21 super.move(distanceInMeters);
22 }
23}
24
25let sam = new Snake("Sammy the Python");
26let tom: Animal = new Horse("Tommy the Palomino");
27
28sam.move();
29tom.move(34);