Prefer Annotating Types Over Asserting #3042
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PULL REQUEST
Summary
Where possible, annotate the returned value of the
evaluate
function instead of asserting it.Related Issue
Fixes # n/a
Acceptance Criteria
n/a
Additional Information
We use the
evaluate
function from thefhirpath
library throughout. the ecr-viewer. However, it is typed to returnany
. To take advantage of type hints in IDEs, we need to either assert the expected type, e.g.,const rrDetails: Observation[] = evaluate(fhirBundle, mappings.rrDetails);
or assert the expected type, e.g.,const rrDetails = evaluate(fhirBundle, mappings.rrDetails) as Observation[];
. Both options more-or-less do the same thing, but there are a few reasons to prefer annotation. In brief it is the difference between saying, "I know the type of this value, and throw an error if it does not fit this type," and "Treat this value as this type no matter what."See: