-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.ts
More file actions
37 lines (30 loc) · 769 Bytes
/
function.ts
File metadata and controls
37 lines (30 loc) · 769 Bytes
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
// functional declaration
function add(x: number, y: number): number {
return x + y
}
let res = add(8, 5)
console.log(res)
// function with callback
type Greeter = (message: string) => void
function req(url: string, callback: Greeter) {
callback(url)
}
let data = (str: string) => console.log(str)
req('http://helo.com', data)
// exercise
type Contact = {
firstName: string,
lastName: string,
gender?: string,
language: string
}
function submitContact(firstName: string, lastName: string, gender?: string, language = 'english'): Contact {
return {
firstName: firstName,
lastName: lastName,
language,
...(gender && { gender })
}
}
let datas = submitContact('fiqry', 'choerudin')
console.log(datas)