Skip to content

Commit fbb7d05

Browse files
committed
Add TypeScript examples
1 parent 6e4de4a commit fbb7d05

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

TypeScript/1-interface.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
interface IDate {
2+
day: number;
3+
month: number;
4+
year: number;
5+
}
6+
7+
interface IPerson {
8+
name: string;
9+
city: string;
10+
born: IDate;
11+
}
12+
13+
// Usage
14+
15+
const p1: IPerson = {
16+
name: 'Marcus',
17+
city: 'Roma',
18+
born: {
19+
day: 26,
20+
month: 4,
21+
year: 121,
22+
},
23+
};
24+
25+
const date = `${p1.born.year}-${p1.born.month}-${p1.born.day}`;
26+
console.log(`Name: ${p1.name}\nCity: ${p1.city}\nBorn: ${date}\n`);

TypeScript/2-class.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class DateStruct {
2+
day: number;
3+
month: number;
4+
year: number;
5+
}
6+
7+
class Person {
8+
name: string;
9+
city: string;
10+
born: DateStruct;
11+
}
12+
13+
// Usage
14+
15+
const p1: Person = {
16+
name: 'Marcus',
17+
city: 'Roma',
18+
born: {
19+
day: 26,
20+
month: 4,
21+
year: 121,
22+
},
23+
};
24+
25+
const date = `${p1.born.year}-${p1.born.month}-${p1.born.day}`;
26+
console.log(`Name: ${p1.name}\nCity: ${p1.city}\nBorn: ${date}\n`);

0 commit comments

Comments
 (0)