Repository navigation
Expand file tree
/
Copy pathapp.ts
More file actions
23 lines (16 loc) · 2.75 KB
/
Copy pathapp.ts
File metadata and controls
23 lines (16 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Working with "optional chaining"
type Customer = {
birthday: Date
};
function getCustomer(id: number): Customer | null | undefined {
return id === 0 ? null : { birthday: new Date() };
}
let customer = getCustomer(1);
//Optional property access operator
console.log(customer?.birthday.getFullYear());
//optional element access operator
//customer?.[0]
//optional call
let log: any = null;
log?.('a');
console.log(log);