Skip to content

Commit

Permalink
chore: add comment to unreachable code path
Browse files Browse the repository at this point in the history
  • Loading branch information
justynoh committed Mar 19, 2024
1 parent f270eea commit 1506a10
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions frontend/src/features/logic/utils/logic-adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})
Expand Down Expand Up @@ -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')
}
})
Expand Down

0 comments on commit 1506a10

Please sign in to comment.