-
Notifications
You must be signed in to change notification settings - Fork 2
/
class.ts
78 lines (57 loc) · 1.35 KB
/
class.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Login, User } from "./interface";
// import * as UserLogin from './interface';
interface Address {
street: string;
city: string;
state: string;
pin: string;
}
class Employee implements Login {
#id: number;
protected name: string;
address: Address;
get empId(): number {
return this.#id;
}
set empId(id: number) {
this.#id = id;
}
static getEmployeeCount(): number {
return 50;
}
constructor(id: number, name: string, address: Address) {
this.address = address;
this.#id = id;
this.name = name;
}
login(): User {
return { name: "John", id: 1, email: "" };
}
getNameWithAddress(): string {
return `${this.name} stays at ${this.address}`;
}
}
let john = new Employee(1, "John", {
street: "ABC",
city: "Bangalore",
state: "Karnataka",
pin: "560076",
});
john.empId = 100;
console.log(john.empId);
// Employee.getEmployeeCount();
class Manager extends Employee {
constructor(id: number, name: string, address: Address) {
super(id, name, address);
}
getNameWithAddress(): string {
return `${this.name} is a manager at ${this.address}`;
}
}
let address = john.getNameWithAddress();
// john.id = 1;
// john.name = "John";
// john.address = "Highway 71";
console.log(address);
let mike = new Manager(2, "Mike", "Cherise Drive");
console.log(mike.getNameWithAddress());