-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
134 lines (96 loc) · 2.63 KB
/
example.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Some Config shit
({
babel: true
})
// Spread
const objectOne:Object = { name: 'Lisa Haber', age: 22 };
const objectTwo:Object = { name: 'Lisa Haber', role: 'Web-Application-Developer' };
const objectThree:Object = { name: 'Tobias Haber', color: 'blue' };
const merged:Object = {...objectOne, ...objectTwo,...objectThree};
console.log(merged);
// Arrow
const justAFunction = (x, y)=> {
return x * y;
};
const output = justAFunction(10,3);
console.log(output);
// Function with dynamic input
const multi = (...input)=>{
console.log(input);
return input[0]+"_first";
}
const initMulti = multi("hallo","das ist ein test","luna");
console.log(initMulti);
// Generators
function* someDragons() {
yield 'fluffykins the lighting dragon'
yield 'waffle the time dragon'
yield 'hardy the dog'
}
const iterator = someDragons()
console.log(iterator.next())
console.log(iterator.next())
console.log(iterator.next())
console.log(iterator.next())
// for loop
const dragons = [ 'cool dragon', 'angry dragon', 'nasty dragon' ]
for (const dragon of dragons) {
console.log(dragon)
}
// TypeScript stuff
import axios, { AxiosResponse } from 'axios';
// Types:
const nummer:Number = 5;
const object:Object = {'some':'data'};
const word:String = "Hallo welt";
const array:Array<String> = ['one','two'];
const array2:Array<Number> = [1,2];
const array3:Array<any> = [1,2,"demo"];
class User {
private _id: Number;
private _name: String;
private _username: String;
private _email: String;
constructor(id: Number, name: String, username: String, email: String) {
this._id = id;
this._name = name;
this._username = username;
this._email = email;
}
get id(): Number {
return this._id;
}
set id(value: Number) {
this._id = value;
}
get name(): String {
return this._name;
}
set name(value: String) {
this._name = value;
}
get username(): String {
return this._username;
}
set username(value: String) {
this._username = value;
}
get email(): String {
return this._email;
}
set email(value: String) {
this._email = value;
}
}
export default User;
const main = async ()=> {
let users: Array<User> = await getUsers();
console.log('Users', users);
}
const getUsers = async (): Promise<Array<User>> =>{
let response: AxiosResponse = await axios.get('https://jsonplaceholder.typicode.com/users');
let users: Array<User> = [];
response.data.forEach((user: User) => users.push(new User(user.id, user.name, user.username, user.email)));
return users;
}
main();