Skip to content

Commit 5fb1bb7

Browse files
committed
An Object type
1 parent 949074d commit 5fb1bb7

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

typescript/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var list1 = [1, 2, 3];
1919
var list2 = [1, 2, 3];
2020
var p1 = ["Sam", 12]; // tuple, fixed dimension
2121
console.log(p1);
22+
//union types
2223
var p2 = ["Sam", 12, "Sue", 45, "Helen"]; // mixed types in array
2324
console.log(p2);
2425
var mixed = ["ome", 2, true];
@@ -55,3 +56,6 @@ console.log(multitype);
5556
multitype = true;
5657
console.log(multitype);
5758
// multitype = 'Hello' ERROR
59+
var anObj;
60+
anObj = { attr1: "hello", attr2: 12 };
61+
console.log(anObj);

typescript/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ let list2: Array<number> = [1,2,3]
2626
let p1: [ string, number ] = ["Sam", 12] // tuple, fixed dimension
2727
console.log(p1)
2828

29+
//union types
2930
let p2: (string | number)[]= ["Sam", 12, "Sue", 45, "Helen"] // mixed types in array
3031
console.log(p2)
3132

@@ -56,4 +57,12 @@ multitype = 1
5657
console.log(multitype)
5758
multitype = true
5859
console.log(multitype)
59-
// multitype = 'Hello' ERROR
60+
// multitype = 'Hello' ERROR
61+
62+
let anObj: {
63+
attr1: string,
64+
attr2: number
65+
}
66+
67+
anObj = {attr1:"hello", attr2: 12}
68+
console.log(anObj)

0 commit comments

Comments
 (0)