Jarod Cavalcante
2020-12-24T19:16:58Z

types-typescript.ts

| // boolean (true / false)
| let isOpen: boolean
| isOpen = true
|
| // string ('foo', "foo", `foo`)
| let message: string
| message = `foo ${isOpen}`
|
| // number
| let total: number
| total = 0xff2
|
| // arrays
| let items: number[]
| items = [1, 2, 3]
|
| let letters: Array<string>
| letters = ['a', 'b', 'c']
|
| // tuple
| let childs: [number, string]
| childs = [1, 'mark']
|
| // enum
| enum Colors {
| white = '#fff',
| black = '#000',
| }
|
| // any (qualquer coisa) NÃO É LEGAL!
| let coisa: any
| coisa = [1, 2, 3]
|
| // 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 = { true: true }