-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.ts
More file actions
34 lines (28 loc) · 725 Bytes
/
Copy pathtype.ts
File metadata and controls
34 lines (28 loc) · 725 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
type NumberOrString = number | string;
let total2: NumberOrString = 10;
total2 = '200';
type Produto = {
nome: string;
preco: number;
teclado: boolean;
};
function preencherDados(dados: Produto) {
document.body.innerHTML += `
<div>
<h2>${dados.nome}</h2>
<p>R$ ${dados.preco}</p>
<p>Inclui teclado: ${dados.teclado ? 'sim' : 'não'}</p>
</div>
`;
}
type Categorias = 'design' | 'codigo' | 'descod';
function pintarCategoria(categoria: Categorias) {
if (categoria === 'design') {
console.log('Pintar vermelho');
} else if (categoria === 'codigo') {
console.log('Pintar verde');
} else if (categoria === 'descod') {
console.log('Pintar roxo');
}
}
pintarCategoria('codigo');