0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-01-11 05:39:10 +00:00
renovatebot_renovate/lib/util/assign-keys.ts
2023-11-07 15:50:29 +00:00

18 lines
477 B
TypeScript

import is from '@sindresorhus/is';
/**
* Assigns non-nullish values from `right` to `left` for the given `keys`.
*/
export function assignKeys<
Left extends { [key in K]?: unknown },
Right extends { [key in K]?: Left[key] },
K extends keyof Right,
>(left: Left, right: Right, keys: K[]): Left {
for (const key of keys) {
const val = right[key];
if (!is.nullOrUndefined(val)) {
left[key] = val as unknown as Left[typeof key];
}
}
return left;
}