-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10-interfaces.ts
More file actions
48 lines (42 loc) · 1.07 KB
/
10-interfaces.ts
File metadata and controls
48 lines (42 loc) · 1.07 KB
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
//An interface defines the "shape" of data.
//It contains the general definition and the structure for a complext type
//It defines types to pass data between components in the application
//Interface is a shared contract in the code
interface User
{
id: number,
name: string,
lastName: string,
password: string
rol: Rol
email?: string, // optional parameter using question mark
resetPassWord(password: string): boolean //you can properties but also functions to an interface
}
interface Rol
{
id: number,
rolName: string,
levelPermission: number
}
// using interfaces
let newRol : Rol =
{
id: 1,
rolName: "Admin",
levelPermission: 0
}
let newUser : User =
{
id: 1,
name: "Miguel",
lastName: "Teheran",
password: "****",
rol: newRol,
resetPassWord: function (password: string): boolean {
this.password = password;
return true;
}
}
//Interface vs Types
// - Interfaces represnt the object data structure
// - Type is a alias to represent primitive types and objects like data structure