diff --git a/10 generics/src/index.ts b/10 generics/src/index.ts index 1c02e23..ef703c9 100644 --- a/10 generics/src/index.ts +++ b/10 generics/src/index.ts @@ -1,8 +1,8 @@ /** A FIFO (First In First Out) collection */ class Queue { - data = []; + public data:T[] = []; push(item: T) { this.data.push(item); } - pop(): T { return this.data.shift(); } + pop(): T { return this.data.shift()! ; } // ! signifies that it can't be undefined } const queue = new Queue(); @@ -10,4 +10,4 @@ queue.push(123); queue.push(456); console.log(queue.pop().toPrecision(1)); -console.log(queue.pop().toPrecision(1)); \ No newline at end of file +console.log(queue.pop().toPrecision(1)); diff --git a/27 narrowing/src/index.ts b/27 narrowing/src/index.ts index 96dc0b7..272cd5c 100644 --- a/27 narrowing/src/index.ts +++ b/27 narrowing/src/index.ts @@ -9,7 +9,7 @@ type Rectangle = { type Shape = Square | Rectangle; -function area(shape: Shape) { +function area(shape: Shape): void|number { if ('size' in shape) { return shape.size * shape.size; } @@ -19,4 +19,4 @@ function area(shape: Shape) { } area({ size: 2 }); // 4 -area({ width: 2, height: 3 }); // 6 \ No newline at end of file +area({ width: 2, height: 3 }); // 6