Skip to content

Commit 2c2bc6d

Browse files
committed
add union
1 parent dc72483 commit 2c2bc6d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

union/myUnion.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
console.log("hello world");
2+
var score = 33;
3+
score = 44;
4+
score = "55";
5+
score = false;
6+
var waseem = { name: "waseem_akram", id: "123" };
7+
waseem = { userName: "fahad iqbal ", adminid: 321 };
8+
// function dbId(id: number | string): number | string {
9+
// //some complex Api calls
10+
// console.log(`The database Id is : ${id}`);
11+
// return 123;
12+
// }
13+
function dbId(id) {
14+
if (typeof id === "string") {
15+
return id.toLowerCase();
16+
}
17+
id.toLocaleString();
18+
}
19+
dbId("123");
20+
dbId(123);
21+
// dbId(false);
22+
//Array
23+
var data = [1, 2, 3, 4, 5, 6];
24+
var data2 = ["waseem", "fahad", "talha"];
25+
var data3 = ["waseem", 1, 2, true];
26+
var pi = 3.14;
27+
// pi = 3.145;
28+
var seatAllotment;
29+
seatAllotment = "window";
30+
// seatAllotment = "crew";

union/myUnion.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
console.log("hello world");
2+
let score: number | string | boolean = 33;
3+
score = 44;
4+
score = "55";
5+
score = false;
6+
7+
type user = {
8+
name: string;
9+
id: string;
10+
};
11+
12+
type admin = {
13+
userName: string;
14+
adminid: number;
15+
};
16+
17+
let waseem: user | admin = { name: "waseem_akram", id: "123" };
18+
waseem = { userName: "fahad iqbal ", adminid: 321 };
19+
20+
// function dbId(id: number | string): number | string {
21+
// //some complex Api calls
22+
// console.log(`The database Id is : ${id}`);
23+
// return 123;
24+
// }
25+
26+
function dbId(id: number | string) {
27+
if (typeof id === "string") {
28+
return id.toLowerCase();
29+
}
30+
id.toLocaleString();
31+
}
32+
33+
dbId("123");
34+
dbId(123);
35+
// dbId(false);
36+
37+
//Array
38+
39+
const data: number[] = [1, 2, 3, 4, 5, 6];
40+
const data2: string[] = ["waseem", "fahad", "talha"];
41+
const data3: (string | number | boolean)[] = ["waseem", 1, 2, true];
42+
43+
let pi: 3.14 = 3.14;
44+
// pi = 3.145;
45+
46+
let seatAllotment: "aisle " | "middle" | "window";
47+
seatAllotment = "window";
48+
// seatAllotment = "crew";

0 commit comments

Comments
 (0)