From e334534bd1e43aefbf7ce97001093b95df2fd77f Mon Sep 17 00:00:00 2001 From: Savy011 <106910589+Savy011@users.noreply.github.com> Date: Sat, 27 May 2023 10:55:28 +0530 Subject: [PATCH] Fixed Default case for switch --- Part_9/courseinfo/src/components/Part.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Part_9/courseinfo/src/components/Part.tsx b/Part_9/courseinfo/src/components/Part.tsx index ff07deb..a11f64d 100644 --- a/Part_9/courseinfo/src/components/Part.tsx +++ b/Part_9/courseinfo/src/components/Part.tsx @@ -1,5 +1,11 @@ import { CoursePart } from '../types'; +const assertNever = (value: never): never => { + throw new Error( + `Unhandled discriminated union member: ${JSON.stringify(value)}` + ) +} + const Part = ({ coursePart }: { coursePart: CoursePart }): JSX.Element => { switch(coursePart.kind) { case "base": @@ -33,7 +39,7 @@ const Part = ({ coursePart }: { coursePart: CoursePart }): JSX.Element => { ); default: - return
+ return assertNever(coursePart) } }; -- 2.51.2