diff --git a/lib/plain/wrappers/wrap.test-d.ts b/lib/plain/wrappers/wrap.test-d.ts index 14c220e06..f2479ac44 100644 --- a/lib/plain/wrappers/wrap.test-d.ts +++ b/lib/plain/wrappers/wrap.test-d.ts @@ -27,4 +27,22 @@ describe('OptionalDefaults', () => { expectTypeOf().toMatchTypeOf() }) + + it('handles intersection types', () => { + type Result = OptionalDefaults<{ foo1: 'bar1' } | { foo2: 'bar2' }> + + type Expected = { foo1: 'bar1' } | { foo2: 'bar2' } + + expectTypeOf().toMatchTypeOf() + }) + + it('handles union with intersection types', () => { + type Result = OptionalDefaults<{ spaceId: string } & ({ foo1: 'bar1' } | { foo2: 'bar2' })> + + type Expected = + | { spaceId?: string | undefined; foo1: 'bar1' } + | { spaceId?: string | undefined; foo2: 'bar2' } + + expectTypeOf().toMatchTypeOf() + }) }) diff --git a/lib/plain/wrappers/wrap.ts b/lib/plain/wrappers/wrap.ts index 322a1f18f..d979b38cb 100644 --- a/lib/plain/wrappers/wrap.ts +++ b/lib/plain/wrappers/wrap.ts @@ -5,11 +5,15 @@ export type DefaultParams = { environmentId?: string organizationId?: string } +/** + * @private + */ +type UnionOmit = T extends unknown ? Omit : never /** * @private */ -export type OptionalDefaults = Omit & +export type OptionalDefaults = UnionOmit & Partial>> /**