From 3b55248a9f268c9777485453f4de5d20fce080cd Mon Sep 17 00:00:00 2001 From: "Th. Ma" Date: Thu, 4 Apr 2024 10:11:37 +0200 Subject: [PATCH] Added solution for exercice 13 introducing unknown type --- ...blocks.solution.1.ts => 13-catch-blocks.solution.4.ts} | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) rename src/{13-catch-blocks.solution.1.ts => 13-catch-blocks.solution.4.ts} (72%) diff --git a/src/13-catch-blocks.solution.1.ts b/src/13-catch-blocks.solution.4.ts similarity index 72% rename from src/13-catch-blocks.solution.1.ts rename to src/13-catch-blocks.solution.4.ts index 0a1723e6..ca11b533 100644 --- a/src/13-catch-blocks.solution.1.ts +++ b/src/13-catch-blocks.solution.4.ts @@ -5,8 +5,12 @@ const tryCatchDemo = (state: "fail" | "succeed") => { if (state === "fail") { throw new Error("Failure!"); } - } catch (e: any) { - return e.message; + } catch (e: unknown) { + if (e instanceof Error) { + return e.message; + } + + return 'Failure!'; } };