-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.ts
51 lines (42 loc) Β· 1.09 KB
/
playground.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
// type Person = {
// name: string;
// age: number;
// };
// interface : make more sense when dealing with Object
// interface PersonLoggerFn {
// (name: string, age: number): string;
// }
class Person {
name: string;
age: number;
constructor(name: string, age: number) {
(this.name = name), (this.age = age);
}
}
// type : make more sense when dealing with function
type PersonLoggerFn = (name: string, age: number) => string;
export default function play() {
const name = "Filip";
const age = 30;
const person: Person = {
name: "John",
age: 32,
};
const logPersonInfo: PersonLoggerFn = (
personName: string,
personAge: number
): string => {
const info = `Name: ${personName}, age: ${personAge}`;
console.log(info);
return info;
};
function logPersonInfo2(person: { name: string; age: number }) {
const info = `Name: ${person.name}, age: ${person.age}`;
console.log(info);
return info;
}
const log = logPersonInfo(name, age);
// logPersonInfo2(person);
// using with "class Person"
logPersonInfo2(new Person("Edward", 2));
}