Skip to content

Commit

Permalink
improve typing of array-omit
Browse files Browse the repository at this point in the history
  • Loading branch information
Masa-Shin committed Sep 9, 2022
1 parent af091d7 commit 5f98fa1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
13 changes: 11 additions & 2 deletions packages/object-omit/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
declare function omit<Obj extends object, Key extends string>(obj: Obj, remove: Key[]): Omit<Obj, Key>;
declare function omit<Obj extends object, Key extends string>(obj: Obj, remove1: Key, ...removeN: Key[]): Omit<Obj, Key>;
declare function omit<Obj extends object, Key extends keyof Obj>(
obj: Obj,
remove: Key[]
): Omit<Obj, Key>;

declare function omit<Obj extends object, Key extends keyof Obj>(
obj: Obj,
remove1: Key,
...removeN: Key[]
): Omit<Obj, Key>;

export default omit
17 changes: 7 additions & 10 deletions packages/object-omit/index.tests.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import omit from './index';

const obj = {
a: 1,
b: 2,
c: 3
a: 1,
b: 2,
c: 3
}

{
const test: { c: number } = omit(obj, ['a', 'b'])
const test: { c: number } = omit(obj, ['a', 'b'])
}
{
const test: { a: number } = omit(obj, ['b', 'c', 'd'])
const test: { a: number, c: number } = omit(obj, ['b', 'b', 'b'])
}
{
const test: { a: number, c: number } = omit(obj, ['b', 'b', 'b'])
}
{
const test: { b: number } = omit(obj, 'a', 'c')
const test: { b: number } = omit(obj, 'a', 'c')
}

// Not OK
Expand Down Expand Up @@ -47,4 +44,4 @@ omit({}, {}, 'a');
// @ts-expect-error
omit({ a: 1 }, { a: 1 });
// @ts-expect-error
omit([1, 2, 3], 0);
omit({ a: 1 }, ['a', 'b']);

0 comments on commit 5f98fa1

Please sign in to comment.