Skip to content

Commit a9cee6f

Browse files
committed
test: add Bundle<T> propagation unit test and fix no-predicate demo
1 parent 2ee3308 commit a9cee6f

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

examples/typescript-r4/resource.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ test("Bundle<T> narrows entry resources without type predicates", () => {
135135
],
136136
};
137137

138-
// Discriminated-union narrowing works without a `r is Observation` predicate
138+
// TS 5.5+ infers the type predicate from the discriminated union — no explicit `r is Observation` needed
139139
const observations: Observation[] = (bundle.entry ?? [])
140140
.map((e) => e.resource)
141-
.filter((r): r is Observation => r?.resourceType === "Observation");
141+
.filter((r) => r?.resourceType === "Observation");
142142

143143
expect(observations).toHaveLength(1);
144144
expect(observations[0]!.id).toBe("glucose-obs-1");

test/api/write-generator/typescript.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ describe("TypeScript Writer Generator", async () => {
3030
expect(bundleTs).toContain("export interface BundleEntry<T extends Resource = Resource>");
3131
expect(bundleTs).toContain("resource?: T");
3232
});
33+
it("generates Bundle with generic entry type (nested generic propagation)", async () => {
34+
const bundleTs = files["generated/types/hl7-fhir-r4-core/Bundle.ts"];
35+
expect(bundleTs).toContain("export interface Bundle<T extends Resource = Resource>");
36+
expect(bundleTs).toContain("entry?: BundleEntry<T>[]");
37+
});
3338
it("generates BundleEntryResponse with generic type-family parameter", async () => {
3439
const bundleTs = files["generated/types/hl7-fhir-r4-core/Bundle.ts"];
3540
expect(bundleTs).toContain("export interface BundleEntryResponse<T extends Resource = Resource>");

0 commit comments

Comments
 (0)