From f32251e488d0a66b02d07929d87a71f05ae19c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20P=C3=A4tzold?= Date: Thu, 9 Jan 2025 10:54:26 +0100 Subject: [PATCH] fix: plain client method argument types for `params` with intersection types (#2503) --- lib/plain/wrappers/wrap.test-d.ts | 18 ++++++++++++++++++ lib/plain/wrappers/wrap.ts | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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>> /**