Skip to content

Commit 8c61c52

Browse files
author
Ben Grynhaus
committed
Fix Omit type to work on types that don't have an index signature
1 parent 56cbbfc commit 8c61c52

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

libs/core/src/lib/declarations/omit.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33

44
import { IndexSignature } from './index-signature';
55
import { KnownKeys } from './known-keys';
6+
import { UnknownKeys } from './unknown-keys';
67

7-
export type Omit<T, K extends keyof T> = Pick<T, Exclude<KnownKeys<T> & keyof T, K>> & IndexSignature<T>;
8+
export type _KnownKeysOmit<T, K extends keyof T> = Pick<T, Exclude<KnownKeys<T> & keyof T, K>>;
9+
export type Omit<T, K extends keyof T> = UnknownKeys<T> extends never
10+
? _KnownKeysOmit<T, K>
11+
: _KnownKeysOmit<T, K> & IndexSignature<T>;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type UnknownKeys<T> = { [K in keyof T]: string extends K ? K : number extends K ? K : never } extends {
2+
[_ in keyof T]: infer U
3+
}
4+
? U
5+
: never;

0 commit comments

Comments
 (0)