TS: Generic BundleEntry<T> and DomainResource<T> for resource-typed fields#109
Merged
TS: Generic BundleEntry<T> and DomainResource<T> for resource-typed fields#109
Conversation
1e68306 to
a2f0afc
Compare
9aa6d19 to
b52d29e
Compare
a2f0afc to
6537262
Compare
…rator Detect fields typed as resource type families (Resource, DomainResource) and emit generic parameters so consumers can narrow the type, e.g. BundleEntry<Patient> gives resource?: Patient.
b52d29e to
ed8cb23
Compare
b2a7483 to
69ecfe1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Depends on #110.
Types like
BundleEntryhave fields typed as a resource base type (Resource,DomainResource) that acts as a type family with many children. This change detects such fields and emits generic parameters so consumers can narrow the type.writer.ts: scan fields for resource type families (viaisResourceIdentifier+resourceChildren().length > 0), build<T extends Resource = Resource>generic declarationsutils.ts: addgenericFieldMapparam toresolveFieldTsType()for generic field substitutionprofile-slices.ts: addextractResourceTypeFromMatch()helper; computetypedBaseTypeonSliceDef(e.g.BundleEntry<Patient>); use it in setters, getters, and flat type aliasesprofile.ts: import matched resource types for type discriminator slicesBefore:
After:
Affected types:
BundleEntry<T>,BundleEntryResponse<T>,DomainResource<T>. Default parameter= Resourcemeans unparameterized usage is unchanged.Tests & examples
DomainResource<Patient>contained narrowing,@ts-expect-errorfor wrong resource typeBundleEntry<Patient>/BundleEntry<Organization>in set/get tests