-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_types.ts
62 lines (47 loc) · 948 Bytes
/
1_types.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
// boolean (true / false)
let isOpen: boolean
isOpen: true
// string ('foo', "foo", `foo`)
let message: string
message: `foo ${isOpen}`
// number (int, float, hex, binary)
let total: number
total = 0xff0
// array (type[])
let items: string[]
items = ["foo", "bar"]
let values: Array<number>
values = [1, 2, 3]
// tuple (array que sei as quantidades de intens e os tipos)
let title: [number, string]
title = [1, "foo"]
// enum
enum Colors {
white = '#fff',
black = '#000'
}
// any (qualquer coisa)
let coisa: any
coisa = [1]
// void (vazio)
function logger(): void {
console.log('foo')
}
// null/undefined
type Bla = string | undefined
// never
function error(): never {
throw new Error('error');
}
// object ()
let cart: object
cart = {
name: 'Chevrolet',
color: 'red'
}
// Type Inference
let message2 = "mensagem definida"
message2 = 'string nova'
window.addEventListener('click', (e) => {
console.log(e.button);
})