-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunion.ts
More file actions
45 lines (37 loc) · 886 Bytes
/
union.ts
File metadata and controls
45 lines (37 loc) · 886 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
35
36
37
38
39
40
41
42
43
44
45
// two type of data include in array
// let score:number | string = 33
// score = 44
// score="njjdnnj"
// type user = {
// id:number,
// name: string,
// }
// type Admin = {
// id:number,
// username: string,
// }
// let hamid : user | Admin = {name:"hamid", id:786}
// hamid ={username:"hamid", id:786}
// Remove or rename the existing declaration of User type
type user = {
id: number;
name: string;
};
type Admin = {
id: number;
username: string;
};
let hamid: user | Admin;
hamid = { name: "hamid", id: 786 };
hamid = { username: "hamid", id: 786 };
function getDbId(id: number | string) {
// making some API
console.log(`Db id is ${id}`);
}
getDbId(3);
getDbId("3");
// multiple type with array
const data: number[] = [1, 2, 3];
const dat2: string[] = ["1", "2", "3"];
const data3: string[] | number[] = [1,2,3];
// still all number or string