-
Notifications
You must be signed in to change notification settings - Fork 0
/
7_type-vs-interface.ts
44 lines (31 loc) · 751 Bytes
/
7_type-vs-interface.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
// Type Alias
// definição
type GameT = {
title: string;
};
type DLCT = {
extra: string;
}
// intersection
type GameCollectionT = GameT & DLCT & { content: boolean };
// implements
class CreateGameT implements GameCollectionT {
title: string;
extra: string;
content: boolean;
}
// declarar função
type getSimilarsT = (title: string) => void
// ================= Diferenças ================= //
// permite declarar tipos primitivos
type IDT = string | number;
// pode declarar tuplas normalmente
type TupleT = [number, number];
[1, 2] as TupleT;
// Apenas uma declaração por escopo
type JQueryT = { a: string };
type JQueryT = { b: string };
// mais recomendado:
// na maioria das vezes
// React - Props
// CONSISTÊNCIA!