From 8305ae2aa4e627fd254f3ecb22c7d7b4806a43ab Mon Sep 17 00:00:00 2001 From: Oguntade Tawheed <59873785+TWEEDOriginal@users.noreply.github.com> Date: Sat, 2 Apr 2022 11:04:18 +0100 Subject: [PATCH 1/2] fix: Fixed undefined and never error --- 10 generics/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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)); From 18268baceda2c46815ba735da1dd26d986c9e5a2 Mon Sep 17 00:00:00 2001 From: Oguntade Tawheed <59873785+TWEEDOriginal@users.noreply.github.com> Date: Sat, 2 Apr 2022 17:56:15 +0100 Subject: [PATCH 2/2] fix: return type Fixes the following error: Line 12: `Not all code paths return a value.` Fixed by adding the type for the return value of area function. --- 27 narrowing/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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