From 72272509c709f69f0892de364d89e002ebc2196b Mon Sep 17 00:00:00 2001 From: unional Date: Sat, 16 Mar 2024 20:41:29 -0700 Subject: [PATCH] fix: simplify Omit --- .changeset/itchy-mails-sleep.md | 5 +++++ packages/type-plus/src/object/omit.spec.ts | 12 +++++++++--- packages/type-plus/src/object/omit.ts | 8 +++----- 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .changeset/itchy-mails-sleep.md diff --git a/.changeset/itchy-mails-sleep.md b/.changeset/itchy-mails-sleep.md new file mode 100644 index 0000000000..dead8e484a --- /dev/null +++ b/.changeset/itchy-mails-sleep.md @@ -0,0 +1,5 @@ +--- +"type-plus": patch +--- + +Simplify `Omit` type as the simpler code is working with typescript 5.4 diff --git a/packages/type-plus/src/object/omit.spec.ts b/packages/type-plus/src/object/omit.spec.ts index 58e57fee86..9ad032f8bc 100644 --- a/packages/type-plus/src/object/omit.spec.ts +++ b/packages/type-plus/src/object/omit.spec.ts @@ -65,12 +65,18 @@ describe('Omit', () => { expect(x.foo).toBe('bar') }) + test('intersection types with generic', () => { type Foo = { a: string, b: string } - function foo(input: Omit): void { - assertType.isString(input.b) + function foo(input: Omit): void { + input.a = '1' + // @ts-expect-error Property 'b' does not exist + input.b = '1' + + // @ts-expect-error Property 'c' does not exist. + input.c = '1' } - foo({ b: '1' }) + foo({ a: '1' }) }) }) diff --git a/packages/type-plus/src/object/omit.ts b/packages/type-plus/src/object/omit.ts index 0ed9490025..4ccf9ed9b0 100644 --- a/packages/type-plus/src/object/omit.ts +++ b/packages/type-plus/src/object/omit.ts @@ -7,11 +7,9 @@ import { reduceByKey } from './reduceKey.js' // by Titian Cernicova-Dragomir // https://github.com/microsoft/TypeScript/issues/28339#issuecomment-463577347 // type-zoo -export type Omit> = T extends T - ? (keyof T extends K - ? {} - : Pick>) - : never +export type Omit> = T extends unknown +? Pick> +: never /** * @deprecated replaced by `Omit`