FHIR.ts icon indicating copy to clipboard operation
FHIR.ts copied to clipboard

FHIR R4's IBundle refers to classes not interfaces

Open dougludlow opened this issue 2 months ago • 1 comments

When attempting to create a bundle object using the R4 interfaces, there are errors because the entry resource which is using an interface is not a Resource. Checking the types, all properties in the IBundle reference classes and there are no interfaces for them (no interface for BundleEntry or BundleLink, for intance).

For example, the following code:

const bundle: IfhirR4.IBundle = {
	resourceType: 'Bundle',
	type: 'collection',
	entry: [
		{
			resource: practitioner,
		},
	],
};

Will produce this error:

error TS2322: Type 'IPractitioner' is not assignable to type 'Resource'.
  Type 'IPractitioner' is not assignable to type 'Patient | Person | Practitioner | RelatedPerson'.
    Type 'IPractitioner' is not assignable to type 'Practitioner'.
      Types of property 'resourceType' are incompatible.
        Type 'string' is not assignable to type '"Practitioner"'

A workaround is to cast the resource as a BundleEntry:

const bundle: IfhirR4.IBundle = {
	resourceType: 'Bundle',
	type: 'collection',
	entry: [
		{
			resource: practitioner,
		} as fhirR4.BundleEntry,
	],
};

dougludlow avatar Oct 09 '25 18:10 dougludlow

Oh, typescript becomes happy when I change the IPractictioner['resourceType'] from string to 'Practitioner'. That may be the play here.

dougludlow avatar Oct 09 '25 18:10 dougludlow