-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst.ts
More file actions
103 lines (86 loc) · 2.37 KB
/
first.ts
File metadata and controls
103 lines (86 loc) · 2.37 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
// typeScript::variabledeclearation
let age: number = 25;
let club: string = 'DevTools';
const isFamous: boolean = false;
let famous: boolean;
// typeScript::function::string
function fullName (firstName:string, lastName:string):string{
return firstName + ' ' + lastName;
}
const user:string = fullName('John', 'Smith');
// typeScript::number::function allawse(not return)
function doubleIt(num:number){
const result = num * 2;
// console.log(result);
return result;
}
const output = doubleIt(10);
console.log('Output value is undefind = ', output);
// typeScript::string::loop
let megaName: string = '';
const friends: string[] = ['sumon', 'sadi', 'john', 'bibi', 'spsumon'];
for (let i = 0; i < friends.length; i++) {
const friend = friends[i];
if (friend.length > megaName.length) {
megaName = friend;
}
}
console.log('meganame is = ', megaName);
// typeScript::odject::any accesse
let player: {
name: string,
age: number,
merraged: boolean
} = {
name: 'sp sumon',
age: 25,
merraged: false,
}
// OR::OBJECT
let player2:{name:string, age:number, merraged:boolean} = {
name: 'sp sumon',
age: 20,
merraged: true
}
// typeScript::interface::object
interface Player {
name: string,
age: number,
salary: number,
merraged: boolean,
wife?: string // For meaning ( ? == optional )
}
// typeScript::interface::object
const messy:Player = {
name: 'messy',
age: 20,
salary: 40000,
merraged: true,
// wife: ''
}
// typeScript::interface::function::object
function getBonus (player: Player, friends: string[]) {
return player.salary * 0.1 + ' ' + friends;
}
const poorPlayer = {age: 20, salary: 10000};
const div = getBonus(messy, ['Tom', 'Tinku']);
console.log(div);
// typeScript::class
class Person {
name: string;
private _partner; // do not accesse out of scope
readonly fatherName: string; // read only but do not changed value
constructor(name:string, father:string) {
this.name = name;
this._partner = name;
this.fatherName = father;
}
getName(): string { // function of class (Do not needed to declear 'function' before function)
return this.name;
}
}
const sam = new Person('Samuel', 'David')
console.log('name', sam.name, sam.fatherName);
const saName: string = sam.getName();
sam.name = 'Ben';
// sam.fatherName = 'Ben Carson';