mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-10-10 13:56:34 +03:00
* chore(deps): update dependency prettier to v3 * Format --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Bierema <nbierema@gmail.com>
27 lines
542 B
TypeScript
27 lines
542 B
TypeScript
const objectKeys =
|
|
Object.keys ||
|
|
function (obj) {
|
|
const keys = [];
|
|
for (const key in obj) {
|
|
if ({}.hasOwnProperty.call(obj, key)) keys.push(key);
|
|
}
|
|
return keys;
|
|
};
|
|
|
|
export default function assign<T extends object, K extends keyof T>(
|
|
obj: T,
|
|
newKey: K,
|
|
newValue: T[K],
|
|
): T {
|
|
const keys = objectKeys(obj);
|
|
const copy: T = {} as T;
|
|
|
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
const key = keys[i];
|
|
copy[key as keyof T] = obj[key as keyof T];
|
|
}
|
|
|
|
copy[newKey] = newValue;
|
|
return copy;
|
|
}
|