From 1506a10aa8da63df9dcaf395bbe60cbe040e99e1 Mon Sep 17 00:00:00 2001 From: Justyn Oh Date: Tue, 19 Mar 2024 09:57:25 +0800 Subject: [PATCH] chore: add comment to unreachable code path --- frontend/src/features/logic/utils/logic-adaptor.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/features/logic/utils/logic-adaptor.ts b/frontend/src/features/logic/utils/logic-adaptor.ts index c3b05e68c3..0fa26121a8 100644 --- a/frontend/src/features/logic/utils/logic-adaptor.ts +++ b/frontend/src/features/logic/utils/logic-adaptor.ts @@ -47,11 +47,15 @@ export const getLogicUnitPreventingSubmit = ({ input: filteredFormInputs[_id], } // Type narrowing to help the typechecker along with complex if-else types + // Unfortunately, this requires the runtime check where isNotLogicableField + // is defined as !isLogicableField, allowing the final "else" case to be + // an unreachable code path. if (isNotLogicableField(fieldTypeAndInput)) { return { _id, fieldType: fieldTypeAndInput.fieldType } } else if (isLogicableField(fieldTypeAndInput)) { return { _id, ...fieldTypeAndInput } } else { + // Unreachable branch throw new Error('Unexpected fallthrough') } }) @@ -91,11 +95,15 @@ export const getVisibleFieldIds = ( input, } // Type narrowing to help the typechecker along with complex if-else types + // Unfortunately, this requires the runtime check where isNotLogicableField + // is defined as !isLogicableField, allowing the final "else" case to be + // an unreachable code path. if (isNotLogicableField(fieldTypeAndInput)) { return { _id: ff._id, fieldType: fieldTypeAndInput.fieldType } } else if (isLogicableField(fieldTypeAndInput)) { return { _id: ff._id, ...fieldTypeAndInput } } else { + // Unreachable branch throw new Error('Unexpected fallthrough') } })