1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/util/omit-keys.ts

23 lines
533 B
TypeScript
Raw Normal View History

interface OmitKeys {
<T extends object, K extends [...(keyof T)[]]>(obj: T, ...keys: K): {
[K2 in Exclude<keyof T, K[number]>]: T[K2];
};
}
// https://stackoverflow.com/questions/53966509/typescript-type-safe-omit-function
export const omitKeys: OmitKeys = (obj, ...keys) => {
const ret = {} as {
[K in keyof typeof obj]: typeof obj[K];
};
let key: keyof typeof obj;
for (key in obj) {
if (!keys.includes(key)) {
ret[key] = obj[key];
}
}
return ret;
};