From 58c78a1748dd4edcafcdd3e6ba5c7e397b86da6f Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Mon, 6 Feb 2023 16:58:48 -0300 Subject: [PATCH] Fix CompatibleSlotContent type (#179) --- src/slot.ts | 6 +++--- test/slot.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/slot.ts b/src/slot.ts index 4dd764ae..aaaa6492 100644 --- a/src/slot.ts +++ b/src/slot.ts @@ -22,8 +22,8 @@ export interface VersionedSlotMap extends LatestSlotVersionMap { */ type Intersection = T extends infer O ? O & E : never; -type UnionContent = { - [K in ComponentVersionId]: Intersection, {_component: K | null}>; +type UnionContent = { + [K in ComponentVersionId]: Intersection, {_component: K | T}>; }; type UnknownContent = UnionContent[ComponentVersionId] extends never @@ -42,7 +42,7 @@ export type SlotVersionId = CanonicalVersionId = VersionedId; -export type CompatibleSlotContent = UnionContent[T]; +export type CompatibleSlotContent = UnionContent[T]; export type SlotContent = JsonObject extends C ? (string extends I ? UnknownContent : VersionedContent) : C; diff --git a/test/slot.test.ts b/test/slot.test.ts index 24c7ef4f..07b95e46 100644 --- a/test/slot.test.ts +++ b/test/slot.test.ts @@ -252,7 +252,7 @@ describe('Slot typing', () => { expect(() => compileCode(code)).not.toThrow(); - expect(getTypeName(code)).toBe('Banner & {_component: "banner@1" | null;}'); + expect(getTypeName(code)).toBe('Banner & {_component: "banner@1";}'); }); it('should export a CompatibleSlotContent type that resolves the slot content type for multiple components', () => { @@ -268,9 +268,9 @@ describe('Slot typing', () => { expect(() => compileCode(code)).not.toThrow(); expect(getTypeName(code)).toBe( - '(Banner & {_component: "banner@1" | null;})' - + ' | (HorizontalBanner & {_type: \'horizontal-banner\';} & {_component: "hybrid-banner@1" | null;})' - + ' | (VerticalBanner & {...;} & {_component: "hybrid-banner@1" | null;})', + '(Banner & {_component: "banner@1";})' + + ' | (HorizontalBanner & {_type: \'horizontal-banner\';} & {_component: "hybrid-banner@1";})' + + ' | (VerticalBanner & {_type: \'vertical-banner\';} & {_component: "hybrid-banner@1";})', ); });