Skip to content

Commit 95d67f2

Browse files
committed
first commit
0 parents  commit 95d67f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+6163
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/*
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"O **Tipo de Afirmação** ou **type assertion** nos permite informar ao compilador o tipo da variavel."
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 3,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"name": "stdout",
17+
"output_type": "stream",
18+
"text": [
19+
"16\n"
20+
]
21+
}
22+
],
23+
"source": [
24+
"let valorInicial: any = \"this is a string\";\n",
25+
"\n",
26+
"let strLength: number = (valorInicial as string).length;\n",
27+
"\n",
28+
"console.log(strLength); "
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 4,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"name": "stdout",
38+
"output_type": "stream",
39+
"text": [
40+
"16\n"
41+
]
42+
}
43+
],
44+
"source": [
45+
"let valorInicial: any = \"this is a string\";\n",
46+
"\n",
47+
"let strLength: number = (<string>valorInicial).length;\n",
48+
"\n",
49+
"console.log(strLength); "
50+
]
51+
}
52+
],
53+
"metadata": {
54+
"kernelspec": {
55+
"display_name": "Deno",
56+
"language": "typescript",
57+
"name": "deno"
58+
},
59+
"language_info": {
60+
"codemirror_mode": "typescript",
61+
"file_extension": ".ts",
62+
"mimetype": "text/x.typescript",
63+
"name": "typescript",
64+
"nbconvert_exporter": "script",
65+
"pygments_lexer": "typescript",
66+
"version": "5.5.2"
67+
}
68+
},
69+
"nbformat": 4,
70+
"nbformat_minor": 2
71+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Os **Guardas de Tipos** (type guards) são uma maneira de definir uma função ou método que verifica se uma variável é de um determinado tipo. "
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"function isString(param: any): value is string {\n",
17+
" return typeof param === \"string\";\n",
18+
"}\n",
19+
"\n",
20+
"function example(value: any) {\n",
21+
" if (isString(value)) {\n",
22+
" console.log(`é uma string`);\n",
23+
" } else {\n",
24+
" console.log(\"não é uma string\");\n",
25+
" }\n",
26+
"}\n"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 3,
32+
"metadata": {},
33+
"outputs": [
34+
{
35+
"name": "stdout",
36+
"output_type": "stream",
37+
"text": [
38+
"não é uma string\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"example(18); "
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 4,
49+
"metadata": {},
50+
"outputs": [
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"não é uma string\n"
56+
]
57+
}
58+
],
59+
"source": [
60+
"example(39);"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"interface Bird {\n",
70+
" fly(): void;\n",
71+
"}\n",
72+
"\n",
73+
"interface Fish {\n",
74+
" swim(): void;\n",
75+
"}"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 5,
81+
"metadata": {},
82+
"outputs": [],
83+
"source": [
84+
"function isBird(animal: any): animal is Bird {\n",
85+
" return (animal as Bird).fly !== undefined;\n",
86+
"}\n",
87+
"\n",
88+
"function example(animal: Bird | Fish) {\n",
89+
" if (isBird(animal)) {\n",
90+
" animal.fly();\n",
91+
" } else {\n",
92+
" animal.swim();\n",
93+
" }\n",
94+
"}"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"Os guardas de tipos são extremamente úteis para garantir a segurança de tipos em TypeScript"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": 9,
107+
"metadata": {},
108+
"outputs": [
109+
{
110+
"name": "stdout",
111+
"output_type": "stream",
112+
"text": [
113+
"Salmon is swimming\n"
114+
]
115+
}
116+
],
117+
"source": [
118+
"class Salmon implements Fish {\n",
119+
" swim() {\n",
120+
" console.log(\"Salmon is swimming\");\n",
121+
" }\n",
122+
" }\n",
123+
"\n",
124+
"const salmon = new Salmon();\n",
125+
"example(salmon)\n"
126+
]
127+
}
128+
],
129+
"metadata": {
130+
"kernelspec": {
131+
"display_name": "Deno",
132+
"language": "typescript",
133+
"name": "deno"
134+
},
135+
"language_info": {
136+
"codemirror_mode": "typescript",
137+
"file_extension": ".ts",
138+
"mimetype": "text/x.typescript",
139+
"name": "typescript",
140+
"nbconvert_exporter": "script",
141+
"pygments_lexer": "typescript",
142+
"version": "5.5.2"
143+
}
144+
},
145+
"nbformat": 4,
146+
"nbformat_minor": 2
147+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"O tipo **índice** (index type) é usado para definir um tipo que pode ser acessado usando uma chave (indexador). \n"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"Vamos criar um exemplo que permite que qualquer chave de string seja usada, com valores de string correspondentes."
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"interface TranslationDictionary {\n",
24+
" [key: string]: string;\n",
25+
"}\n",
26+
"\n",
27+
"let translations: TranslationDictionary = {\n",
28+
" en: \"Hello\",\n",
29+
" pt: \"Olá\",\n",
30+
" fr: \"Bonjour\",\n",
31+
" es: \"Hola\"\n",
32+
"};"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"metadata": {},
39+
"outputs": [
40+
{
41+
"name": "stdout",
42+
"output_type": "stream",
43+
"text": [
44+
"Hello\n"
45+
]
46+
}
47+
],
48+
"source": [
49+
"console.log(translations['en']); "
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 3,
55+
"metadata": {},
56+
"outputs": [
57+
{
58+
"name": "stdout",
59+
"output_type": "stream",
60+
"text": [
61+
"Olá\n"
62+
]
63+
}
64+
],
65+
"source": [
66+
"console.log(translations['pt']);"
67+
]
68+
}
69+
],
70+
"metadata": {
71+
"kernelspec": {
72+
"display_name": "Deno",
73+
"language": "typescript",
74+
"name": "deno"
75+
},
76+
"language_info": {
77+
"codemirror_mode": "typescript",
78+
"file_extension": ".ts",
79+
"mimetype": "text/x.typescript",
80+
"name": "typescript",
81+
"nbconvert_exporter": "script",
82+
"pygments_lexer": "typescript",
83+
"version": "5.5.2"
84+
}
85+
},
86+
"nbformat": 4,
87+
"nbformat_minor": 2
88+
}

0 commit comments

Comments
 (0)