Skip to content

Commit

Permalink
Added readonly to keys for pick and omit
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Apr 19, 2024
1 parent d5e28b2 commit d10bdda
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export function filterObject<O extends object, R extends object>(object: O, pred
return <R>Object.fromEntries(entries.filter(([key, value]) => predicate(key, value)));
}

export function pick<T extends object, K extends keyof T>(object: T, ...keys: K[] | K[][]): Pick<T, K> {
export function pick<T extends object, K extends keyof T>(object: T, ...keys: readonly K[] | readonly K[][]): Pick<T, K> {
return filterObject<T, Pick<T, K>>(object, (key: K) => keys.flat().includes(key));
}

export function omit<T extends object, K extends keyof T>(object: T, ...keys: K[] | K[][]): Omit<T, K> {
export function omit<T extends object, K extends keyof T>(object: T, ...keys: readonly K[] | readonly K[][]): Omit<T, K> {
return filterObject<T, Omit<T, K>>(object, (key: K) => !keys.flat().includes(key));
}

Expand Down

0 comments on commit d10bdda

Please sign in to comment.