export const isVoid = (value: unknown) => value === undefined || value === null || value === "";// let a: object// a = {name: 'jack'}// a = () => {// }// a = new RegExp('')//// let b: { [key: string]: unknown }// b = {name: 'Jack'}// b = () => {}// 在一个函数里,改变传入的对象本身是不好的export const cleanObject = (object?: { [key: string]: unknown }) => { // Object.assign({}, object) if (!object) { return {}; } const result = { ...object }; Object.keys(result).forEach((key) => { const value = result[key]; if (isVoid(value)) { delete result[key]; } }); return result;};
姓名不为空
手机不正确
公司不为空