added some exercise bits to step 2.1

This commit is contained in:
Ken
2019-02-18 14:45:00 -08:00
parent f24ec319f1
commit ac9e68e045
14 changed files with 149 additions and 189 deletions

View File

@@ -1,6 +1,6 @@
// Destructuring
var [x, y, ...rest] = [1, 2, 3, 4];
console.log(x, y, rest); // 1,2,[3,4]
var [a, b, ...rest] = [1, 2, 3, 4];
console.log(a, b, rest); // 1,2,[3,4]
// Array assignment
var list = [1, 2];
@@ -11,5 +11,14 @@ console.log(list); // [1,2,3,4]
const point2D = { x: 1, y: 2 };
const point3D = { ...point2D, z: 3 };
// Concat two objects
const obj1 = { x: 1 };
const obj2 = { y: 2 };
const obj3 = { ...obj1, ...obj2 };
// Destructuring object
const { x } = obj3;
// adding an export to turn this into a "module"
export default {};

View File

@@ -26,12 +26,16 @@ type Specific2 = {
};
// composition
type typeofObj = {
type TypeOfObj = {
foo: string;
bar: number;
obj: Specific1;
obj1: Specific1;
obj2: Specific2;
};
// Get types by property
type Obj1Type = TypeOfObj['obj1'];
// union, intersection
type Union = Specific1 | Specific2;
type Intersection = Specific1 & Specific2;