Skip to content

Commit

Permalink
fix(associative): update arg types and generics for selectKeys()/with…
Browse files Browse the repository at this point in the history
…outKeys()
  • Loading branch information
postspectacular committed Aug 20, 2023
1 parent f142348 commit 4fa9ea1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 5 additions & 4 deletions packages/associative/src/select-keys.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Keys } from "@thi.ng/api";
import { empty } from "./empty.js";

/**
Expand Down Expand Up @@ -44,13 +45,13 @@ export const selectDefinedKeysMap = <K, V>(
* @param src - source object
* @param ks - selected keys
*/
export const selectKeysObj = <T extends object, K extends keyof T>(
export const selectKeysObj = <T extends object>(
src: T,
ks: Iterable<K>
ks: Iterable<Keys<T>>
): Partial<T> => {
const dest: any = {};
const dest: Partial<T> = {};
for (let k of ks) {
src.hasOwnProperty(k) && (dest[k] = (<any>src)[<any>k]);
src.hasOwnProperty(k) && (dest[k] = src[k]);
}
return dest;
};
Expand Down
14 changes: 8 additions & 6 deletions packages/associative/src/without-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IObjectOf } from "@thi.ng/api";
import type { Keys } from "@thi.ng/api";
import { ensureSet } from "./checks.js";
import { empty } from "./empty.js";

Expand All @@ -12,14 +12,16 @@ export const withoutKeysMap = <K, V>(src: Map<K, V>, keys: Iterable<K>) => {
return dest;
};

export const withoutKeysObj = <T>(
src: IObjectOf<T>,
keys: Iterable<PropertyKey>
export const withoutKeysObj = <T extends object>(
src: T,
keys: Iterable<Keys<T>>
) => {
const ks = ensureSet(keys);
const dest: IObjectOf<T> = {};
const dest: Partial<T> = {};
for (let k in src) {
src.hasOwnProperty(k) && !ks.has(k) && (dest[k] = src[<any>k]);
src.hasOwnProperty(k) &&
!ks.has(<Keys<T>>k) &&
(dest[k] = src[<Keys<T>>k]);
}
return dest;
};

0 comments on commit 4fa9ea1

Please sign in to comment.