Files
iot-device-management-frontend/apps/web-ele/src/utils/bean.ts

20 lines
682 B
TypeScript
Raw Normal View History

2025-09-01 22:24:15 +08:00
// TODO @xingyu要不要抽到 package 里?
/**
* target: {a:1} source:{a:2,b:3} {a:2}
* @param target
* @param source
*/
export const copyValueToTarget = (target: any, source: any) => {
const newObj = Object.assign({}, target, source);
// 删除多余属性
Object.keys(newObj).forEach((key) => {
// 如果不是target中的属性则删除
2025-08-31 21:17:11 +08:00
if (!Object.keys(target).includes(key)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete newObj[key];
}
});
// 更新目标对象值
Object.assign(target, newObj);
};