-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementingInterfaces.ts
More file actions
109 lines (102 loc) · 3.21 KB
/
implementingInterfaces.ts
File metadata and controls
109 lines (102 loc) · 3.21 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***** Implementing interfaces from interfaces.ts *****/
// GetSubscriptionMember and SubscriptionMember is from the interfaces.ts file
import { GetSubscriptionMember, SubscriptionMember } from './interfaces'
// can use aliases if wanted
// import * as Subscriptions from './interfaces'
class GetSubscription implements GetSubscriptionMember {
GetSubscriptionMember(): SubscriptionMember {
// return SubscriptionMember object
return {
subscriptionFee: 10,
enrollmentDate: new Date(2020, 6, 1),
enrollmentStatus: 'A',
id: 1,
firstName: 'John',
lastName: 'Smith',
email: 'some@email.com',
phone: '555-555-5555',
address: {
addressLineOne: '',
city: 'Dallas',
state: 'TX',
country: 'USA',
postalCode: '55555-0000'
}
}
}
}
// get the subscription
const subscription = new GetSubscription();
console.log('Getting subscription member...');
let member = subscription.GetSubscriptionMember();
console.log(member);
console.log();
// deconstruct the returned object
// can also alias the property by assigning a name after a colon ':'
// example: {id: memberId}
let { id: memberId, firstName, lastName, address }: SubscriptionMember = member;
console.log(`Destructured properties: MemberId: ${memberId}, First Name: ${firstName}, Last Name: ${lastName}, Address: ${address.city}, ${address.state}`);
console.log();
// deconstruct arrays example
// member1: first index, member2: second index, ...restMembers: remaining array indexes
let [member1, member2, ...restMembers]: SubscriptionMember[] = [
{
subscriptionFee: 10,
enrollmentDate: new Date(2020, 6, 1),
enrollmentStatus: 'A',
id: 1,
firstName: 'John',
lastName: 'Smith',
email: 'some@email.com',
phone: '555-555-5555',
address: {
addressLineOne: '',
city: 'Dallas',
state: 'TX',
country: 'USA',
postalCode: '55555-0000'
}
},
{
subscriptionFee: 11,
enrollmentDate: new Date(2021, 1, 1),
enrollmentStatus: 'A',
id: 1,
firstName: 'Jane',
lastName: 'Doe',
email: 'some@email.com',
phone: '555-555-5555',
address: {
addressLineOne: '',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '22222-0000'
}
},
{
subscriptionFee: 10,
enrollmentDate: new Date(2000, 3, 14),
enrollmentStatus: 'A',
id: 1,
firstName: 'Homer',
lastName: 'Simpson',
email: 'some@email.com',
phone: '555-555-5555',
address: {
addressLineOne: '',
city: 'Springfield',
state: 'IL',
country: 'USA',
postalCode: '44444-0000'
}
}
]
console.log(`Member one: ${member1.firstName}`);
console.log(member1);
console.log(`Member two: ${member2.firstName}`);
console.log(member2);
console.log(`Remaining member(s): ${restMembers.length}`);
console.log(restMembers);
console.log();
export { }