diff --git a/types/fhir/index.d.ts b/types/fhir/index.d.ts
index 89fb556d91693c..a0109335ea9857 100644
--- a/types/fhir/index.d.ts
+++ b/types/fhir/index.d.ts
@@ -1,5 +1,6 @@
// Type definitions for non-npm package FHIR
// Project: http://hl7.org/fhir/index.html
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
//
// Generated with https://github.com/reason-healthcare/fhir-types-workspace/tree/main/packages/fhir-ts-codegen
///
diff --git a/types/fhir/r2.d.ts b/types/fhir/r2.d.ts
index 00a0e2331dcf6f..a1880c8d2cde28 100644
--- a/types/fhir/r2.d.ts
+++ b/types/fhir/r2.d.ts
@@ -13190,6 +13190,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
* Base StructureDefinition for Resource Resource
*/
export interface Resource {
+ /** Resource Type Name (for serialization) */
+ readonly resourceType: string;
/**
* Logical id of this artifact
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
diff --git a/types/fhir/r3.d.ts b/types/fhir/r3.d.ts
index acfeea0a288f40..4ed56f38d30633 100644
--- a/types/fhir/r3.d.ts
+++ b/types/fhir/r3.d.ts
@@ -14777,6 +14777,12 @@ export interface MedicationPackage extends BackboneElement {
batch?: MedicationPackageBatch[] | undefined;
}
+/**
+ * A fixed quantity (no comparator)
+ */
+export interface SimpleQuantity extends Quantity {
+}
+
/**
* Base StructureDefinition for DiagnosticReport Resource
*/
@@ -20780,6 +20786,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
* Base StructureDefinition for Resource Resource
*/
export interface Resource {
+ /** Resource Type Name (for serialization) */
+ readonly resourceType: string;
/**
* Logical id of this artifact
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
diff --git a/types/fhir/r4.d.ts b/types/fhir/r4.d.ts
index c678d95982f56c..948f605def022e 100644
--- a/types/fhir/r4.d.ts
+++ b/types/fhir/r4.d.ts
@@ -18656,6 +18656,12 @@ export interface MedicationBatch extends BackboneElement {
_expirationDate?: Element | undefined;
}
+/**
+ * A fixed quantity (no comparator)
+ */
+export interface SimpleQuantity extends Quantity {
+}
+
/**
* The findings and interpretation of diagnostic tests performed on patients, groups of patients, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting and provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports.
*/
@@ -28032,6 +28038,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
* This is the base resource type for everything.
*/
export interface Resource {
+ /** Resource Type Name (for serialization) */
+ readonly resourceType: string;
/**
* Logical id of this artifact
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
@@ -33334,6 +33342,12 @@ export interface MedicinalProductContraindicationOtherTherapy extends BackboneEl
medicationReference?: Reference | undefined;
}
+/**
+ * An amount of money. With regard to precision, see [Decimal Precision](datatypes.html#precision)
+ */
+export interface MoneyQuantity extends Quantity {
+}
+
/**
* Measurements and simple assertions made about a patient, device or other subject.
*/
diff --git a/types/fhir/r4b.d.ts b/types/fhir/r4b.d.ts
index 061fa593584045..380bb21057cd25 100644
--- a/types/fhir/r4b.d.ts
+++ b/types/fhir/r4b.d.ts
@@ -19430,6 +19430,12 @@ export interface MedicationBatch extends BackboneElement {
_expirationDate?: Element | undefined;
}
+/**
+ * A fixed quantity (no comparator)
+ */
+export interface SimpleQuantity extends Quantity {
+}
+
/**
* The findings and interpretation of diagnostic tests performed on patients, groups of patients, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting and provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports.
*/
@@ -28408,6 +28414,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
* This is the base resource type for everything.
*/
export interface Resource {
+ /** Resource Type Name (for serialization) */
+ readonly resourceType: string;
/**
* Logical id of this artifact
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
@@ -34413,6 +34421,12 @@ export interface Quantity extends Element {
_code?: Element | undefined;
}
+/**
+ * An amount of money. With regard to precision, see [Decimal Precision](datatypes.html#precision)
+ */
+export interface MoneyQuantity extends Quantity {
+}
+
/**
* An ingredient of a manufactured item or pharmaceutical product.
*/
diff --git a/types/fhir/r5.d.ts b/types/fhir/r5.d.ts
index f9a6d84b149a1d..c67d6c32a4d190 100644
--- a/types/fhir/r5.d.ts
+++ b/types/fhir/r5.d.ts
@@ -23450,6 +23450,12 @@ export interface MedicationBatch extends BackboneElement {
_expirationDate?: Element | undefined;
}
+/**
+ * A fixed quantity (no comparator)
+ */
+export interface SimpleQuantity extends Quantity {
+}
+
/**
* The findings and interpretation of diagnostic tests performed on patients, groups of patients, products, substances, devices, and locations, and/or specimens derived from these. The report includes clinical context such as requesting provider information, and some mix of atomic results, images, textual and coded interpretations, and formatted representation of diagnostic reports. The report also includes non-clinical context such as batch analysis and stability reporting of products and substances.
*/
@@ -34968,6 +34974,8 @@ export interface ImmunizationRecommendationRecommendation extends BackboneElemen
* This is the base resource type for everything.
*/
export interface Resource extends Base {
+ /** Resource Type Name (for serialization) */
+ readonly resourceType: string;
/**
* Logical id of this artifact
* The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.
@@ -43000,6 +43008,12 @@ export interface Quantity extends DataType {
_code?: Element | undefined;
}
+/**
+ * An amount of money. With regard to precision, see [Decimal Precision](datatypes.html#precision)
+ */
+export interface MoneyQuantity extends Quantity {
+}
+
/**
* An ingredient of a manufactured item or pharmaceutical product.
*/
diff --git a/types/fhir/test/r2-tests.ts b/types/fhir/test/r2-tests.ts
index 234fd13bc22938..8fddf158baf8fc 100644
--- a/types/fhir/test/r2-tests.ts
+++ b/types/fhir/test/r2-tests.ts
@@ -265,3 +265,54 @@ const r2Test5710: fhir2.ValueSet = {"resourceType":"ValueSet","id":"account-stat
// VisionPrescription-33123.json
const r2Test6726: fhir2.VisionPrescription = {"dateWritten":"2014-06-15","dispense":[{"add":2,"base":"down","eye":"right","prism":0.5,"product":{"code":"lens","system":"http://hl7.org/fhir/ex-visionprescriptionproduct"},"sphere":-2},{"add":2,"axis":180,"base":"up","cylinder":-0.5,"eye":"left","prism":0.5,"product":{"code":"lens","system":"http://hl7.org/fhir/ex-visionprescriptionproduct"},"sphere":-1}],"id":"33123","identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"patient":{"reference":"Patient/example"},"prescriber":{"reference":"Practitioner/example"},"resourceType":"VisionPrescription","text":{"div":"
\n\t
OD -2.00 SPH +2.00 add 0.5 p.d. BD
\n
OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU
\n
","status":"generated"}};
+
+// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
+// FhirResource must not circularly reference itself (TS2456).
+// The root cause was that DomainResource.contained (and similar fields) were typed as
+// FhirResource[] instead of Resource[], creating a cycle through every resource type.
+
+// 1. FhirResource is assignable from any concrete resource type
+const r2FhirResourcePatient: fhir2.FhirResource = { resourceType: "Patient", id: "pt-1" };
+const r2FhirResourceObservation: fhir2.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
+
+// 2. FhirResource discriminated union narrows correctly via resourceType
+function processR2FhirResource(resource: fhir2.FhirResource): string {
+ if (resource.resourceType === "Patient") {
+ const patient: fhir2.Patient = resource;
+ return patient.resourceType;
+ }
+ if (resource.resourceType === "Observation") {
+ const obs: fhir2.Observation = resource;
+ return obs.resourceType;
+ }
+ return resource.resourceType;
+}
+processR2FhirResource(r2FhirResourcePatient);
+processR2FhirResource(r2FhirResourceObservation);
+
+// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
+const r2InlineObs: fhir2.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
+const r2PatientWithContained: fhir2.Patient = {
+ resourceType: "Patient",
+ id: "pt-contained",
+ contained: [r2InlineObs],
+};
+
+// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
+const r2InlinePatient: fhir2.Patient = { resourceType: "Patient", id: "pt-1" };
+const r2Params: fhir2.Parameters = {
+ resourceType: "Parameters",
+ parameter: [{ name: "subject", resource: r2InlinePatient }],
+};
+
+// 5. Resource.resourceType is accessible on base-typed fields
+// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
+// BundleEntry.resource is typed as Resource — resourceType must be reachable.
+const r2Bundle: fhir2.Bundle = {
+ resourceType: "Bundle",
+ type: "collection",
+ entry: [{ resource: r2InlinePatient }],
+};
+const r2HasPatient = r2Bundle.entry?.some(
+ (e) => e.resource?.resourceType === "Patient",
+);
diff --git a/types/fhir/test/r3-tests.ts b/types/fhir/test/r3-tests.ts
index 802a0248661d78..078cb2d236ac03 100644
--- a/types/fhir/test/r3-tests.ts
+++ b/types/fhir/test/r3-tests.ts
@@ -337,3 +337,54 @@ const r3Test7131: fhir3.ValueSet = {"resourceType":"ValueSet","id":"abstract-typ
// VisionPrescription-33123.json
const r3Test8285: fhir3.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"\n\t
OD -2.00 SPH +2.00 add 0.5 p.d. BD
\n
OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU
\n
"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"dispense":[{"product":{"coding":[{"system":"http://hl7.org/fhir/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":0.5,"base":"down","add":2},{"product":{"coding":[{"system":"http://hl7.org/fhir/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":0.5,"base":"up","add":2}]};
+
+// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
+// FhirResource must not circularly reference itself (TS2456).
+// The root cause was that DomainResource.contained (and similar fields) were typed as
+// FhirResource[] instead of Resource[], creating a cycle through every resource type.
+
+// 1. FhirResource is assignable from any concrete resource type
+const r3FhirResourcePatient: fhir3.FhirResource = { resourceType: "Patient", id: "pt-1" };
+const r3FhirResourceObservation: fhir3.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
+
+// 2. FhirResource discriminated union narrows correctly via resourceType
+function processR3FhirResource(resource: fhir3.FhirResource): string {
+ if (resource.resourceType === "Patient") {
+ const patient: fhir3.Patient = resource;
+ return patient.resourceType;
+ }
+ if (resource.resourceType === "Observation") {
+ const obs: fhir3.Observation = resource;
+ return obs.resourceType;
+ }
+ return resource.resourceType;
+}
+processR3FhirResource(r3FhirResourcePatient);
+processR3FhirResource(r3FhirResourceObservation);
+
+// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
+const r3InlineObs: fhir3.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
+const r3PatientWithContained: fhir3.Patient = {
+ resourceType: "Patient",
+ id: "pt-contained",
+ contained: [r3InlineObs],
+};
+
+// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
+const r3InlinePatient: fhir3.Patient = { resourceType: "Patient", id: "pt-1" };
+const r3Params: fhir3.Parameters = {
+ resourceType: "Parameters",
+ parameter: [{ name: "subject", resource: r3InlinePatient }],
+};
+
+// 5. Resource.resourceType is accessible on base-typed fields
+// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
+// BundleEntry.resource is typed as Resource — resourceType must be reachable.
+const r3Bundle: fhir3.Bundle = {
+ resourceType: "Bundle",
+ type: "collection",
+ entry: [{ resource: r3InlinePatient }],
+};
+const r3HasPatient = r3Bundle.entry?.some(
+ (e) => e.resource?.resourceType === "Patient",
+);
diff --git a/types/fhir/test/r4-tests.ts b/types/fhir/test/r4-tests.ts
index d8052ab70153b2..5a89dba1231d73 100644
--- a/types/fhir/test/r4-tests.ts
+++ b/types/fhir/test/r4-tests.ts
@@ -409,3 +409,54 @@ const r4Test5306: fhir4.VerificationResult = {"resourceType":"VerificationResult
// VisionPrescription-33123.json
const r4Test5307: fhir4.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"\n\t\t\t
OD -2.00 SPH +2.00 add 0.5 p.d. BD
\n\t\t\t
OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU
\n\t\t
"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","created":"2014-06-15","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"lensSpecification":[{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":[{"amount":0.5,"base":"down"}],"add":2},{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":[{"amount":0.5,"base":"up"}],"add":2}]};
+
+// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
+// FhirResource must not circularly reference itself (TS2456).
+// The root cause was that DomainResource.contained (and similar fields) were typed as
+// FhirResource[] instead of Resource[], creating a cycle through every resource type.
+
+// 1. FhirResource is assignable from any concrete resource type
+const r4FhirResourcePatient: fhir4.FhirResource = { resourceType: "Patient", id: "pt-1" };
+const r4FhirResourceObservation: fhir4.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
+
+// 2. FhirResource discriminated union narrows correctly via resourceType
+function processR4FhirResource(resource: fhir4.FhirResource): string {
+ if (resource.resourceType === "Patient") {
+ const patient: fhir4.Patient = resource;
+ return patient.resourceType;
+ }
+ if (resource.resourceType === "Observation") {
+ const obs: fhir4.Observation = resource;
+ return obs.resourceType;
+ }
+ return resource.resourceType;
+}
+processR4FhirResource(r4FhirResourcePatient);
+processR4FhirResource(r4FhirResourceObservation);
+
+// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
+const r4InlineObs: fhir4.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
+const r4PatientWithContained: fhir4.Patient = {
+ resourceType: "Patient",
+ id: "pt-contained",
+ contained: [r4InlineObs],
+};
+
+// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
+const r4InlinePatient: fhir4.Patient = { resourceType: "Patient", id: "pt-1" };
+const r4Params: fhir4.Parameters = {
+ resourceType: "Parameters",
+ parameter: [{ name: "subject", resource: r4InlinePatient }],
+};
+
+// 5. Resource.resourceType is accessible on base-typed fields
+// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
+// BundleEntry.resource is typed as Resource — resourceType must be reachable.
+const r4Bundle: fhir4.Bundle = {
+ resourceType: "Bundle",
+ type: "collection",
+ entry: [{ resource: r4InlinePatient }],
+};
+const r4HasPatient = r4Bundle.entry?.some(
+ (e) => e.resource?.resourceType === "Patient",
+);
diff --git a/types/fhir/test/r4b-tests.ts b/types/fhir/test/r4b-tests.ts
index 35fe697b211991..16ae3605f38e03 100644
--- a/types/fhir/test/r4b-tests.ts
+++ b/types/fhir/test/r4b-tests.ts
@@ -403,3 +403,54 @@ const r4bTest2838: fhir4b.VerificationResult = {"resourceType":"VerificationResu
// VisionPrescription-33123.json
const r4bTest2839: fhir4b.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"\n\t\t\t
OD -2.00 SPH +2.00 add 0.5 p.d. BD
\n\t\t\t
OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU
\n\t\t
"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","created":"2014-06-15","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"lensSpecification":[{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":[{"amount":0.5,"base":"down"}],"add":2},{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":[{"amount":0.5,"base":"up"}],"add":2}],"meta":{"tag":[{"system":"http://terminology.hl7.org/CodeSystem/v3-ActReason","code":"HTEST","display":"test health data"}]}};
+
+// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
+// FhirResource must not circularly reference itself (TS2456).
+// The root cause was that DomainResource.contained (and similar fields) were typed as
+// FhirResource[] instead of Resource[], creating a cycle through every resource type.
+
+// 1. FhirResource is assignable from any concrete resource type
+const r4bFhirResourcePatient: fhir4b.FhirResource = { resourceType: "Patient", id: "pt-1" };
+const r4bFhirResourceObservation: fhir4b.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
+
+// 2. FhirResource discriminated union narrows correctly via resourceType
+function processR4bFhirResource(resource: fhir4b.FhirResource): string {
+ if (resource.resourceType === "Patient") {
+ const patient: fhir4b.Patient = resource;
+ return patient.resourceType;
+ }
+ if (resource.resourceType === "Observation") {
+ const obs: fhir4b.Observation = resource;
+ return obs.resourceType;
+ }
+ return resource.resourceType;
+}
+processR4bFhirResource(r4bFhirResourcePatient);
+processR4bFhirResource(r4bFhirResourceObservation);
+
+// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
+const r4bInlineObs: fhir4b.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
+const r4bPatientWithContained: fhir4b.Patient = {
+ resourceType: "Patient",
+ id: "pt-contained",
+ contained: [r4bInlineObs],
+};
+
+// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
+const r4bInlinePatient: fhir4b.Patient = { resourceType: "Patient", id: "pt-1" };
+const r4bParams: fhir4b.Parameters = {
+ resourceType: "Parameters",
+ parameter: [{ name: "subject", resource: r4bInlinePatient }],
+};
+
+// 5. Resource.resourceType is accessible on base-typed fields
+// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
+// BundleEntry.resource is typed as Resource — resourceType must be reachable.
+const r4bBundle: fhir4b.Bundle = {
+ resourceType: "Bundle",
+ type: "collection",
+ entry: [{ resource: r4bInlinePatient }],
+};
+const r4bHasPatient = r4bBundle.entry?.some(
+ (e) => e.resource?.resourceType === "Patient",
+);
diff --git a/types/fhir/test/r5-tests.ts b/types/fhir/test/r5-tests.ts
index 7a125f2d857e4b..fd055823deb713 100644
--- a/types/fhir/test/r5-tests.ts
+++ b/types/fhir/test/r5-tests.ts
@@ -448,3 +448,54 @@ const r5Test2820: fhir5.VerificationResult = {"resourceType":"VerificationResult
// VisionPrescription-33123.json
const r5Test2821: fhir5.VisionPrescription = {"resourceType":"VisionPrescription","id":"33123","text":{"status":"generated","div":"\n\t\t\t
OD -2.00 SPH +2.00 add 0.5 p.d. BD
\n\t\t\t
OS -1.00 -0.50 x 180 +2.00 add 0.5 p.d. BU
\n\t\t
"},"identifier":[{"system":"http://www.happysight.com/prescription","value":"15013"}],"status":"active","created":"2014-06-15","patient":{"reference":"Patient/example"},"dateWritten":"2014-06-15","prescriber":{"reference":"Practitioner/example"},"lensSpecification":[{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"right","sphere":-2,"prism":[{"amount":0.5,"base":"down"}],"add":2},{"product":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct","code":"lens"}]},"eye":"left","sphere":-1,"cylinder":-0.5,"axis":180,"prism":[{"amount":0.5,"base":"up"}],"add":2}],"meta":{"tag":[{"system":"http://terminology.hl7.org/CodeSystem/v3-ActReason","code":"HTEST","display":"test health data"}]}};
+
+// Regression tests for https://github.com/DefinitelyTyped/DefinitelyTyped/issues/71984
+// FhirResource must not circularly reference itself (TS2456).
+// The root cause was that DomainResource.contained (and similar fields) were typed as
+// FhirResource[] instead of Resource[], creating a cycle through every resource type.
+
+// 1. FhirResource is assignable from any concrete resource type
+const r5FhirResourcePatient: fhir5.FhirResource = { resourceType: "Patient", id: "pt-1" };
+const r5FhirResourceObservation: fhir5.FhirResource = { resourceType: "Observation", id: "obs-1", status: "final", code: { text: "test" } };
+
+// 2. FhirResource discriminated union narrows correctly via resourceType
+function processR5FhirResource(resource: fhir5.FhirResource): string {
+ if (resource.resourceType === "Patient") {
+ const patient: fhir5.Patient = resource;
+ return patient.resourceType;
+ }
+ if (resource.resourceType === "Observation") {
+ const obs: fhir5.Observation = resource;
+ return obs.resourceType;
+ }
+ return resource.resourceType;
+}
+processR5FhirResource(r5FhirResourcePatient);
+processR5FhirResource(r5FhirResourceObservation);
+
+// 3. DomainResource.contained uses Resource[] (not FhirResource[]) — no circularity
+const r5InlineObs: fhir5.Observation = { resourceType: "Observation", id: "inline-obs", status: "final", code: { text: "test" } };
+const r5PatientWithContained: fhir5.Patient = {
+ resourceType: "Patient",
+ id: "pt-contained",
+ contained: [r5InlineObs],
+};
+
+// 4. ParametersParameter.resource uses Resource (not FhirResource) — no circularity
+const r5InlinePatient: fhir5.Patient = { resourceType: "Patient", id: "pt-1" };
+const r5Params: fhir5.Parameters = {
+ resourceType: "Parameters",
+ parameter: [{ name: "subject", resource: r5InlinePatient }],
+};
+
+// 5. Resource.resourceType is accessible on base-typed fields
+// Regression for https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/75015
+// BundleEntry.resource is typed as Resource — resourceType must be reachable.
+const r5Bundle: fhir5.Bundle = {
+ resourceType: "Bundle",
+ type: "collection",
+ entry: [{ resource: r5InlinePatient }],
+};
+const r5HasPatient = r5Bundle.entry?.some(
+ (e) => e.resource?.resourceType === "Patient",
+);