试试这个是否符合你的需求 // 必须这样写,不能让ts自行推断 let rename: { type: 'product_type', teacher_name: 'name', } = { type: 'product_type', teacher_name: 'name', }; // 如果使用typescript>=3.4,可以使用const断言,更加简洁 let rename = { type: 'product_type', teacher_name: 'name', } as const; function reobjectKeys<V, T extends { [key: string]: keyof V }>(obj: V, rule: T): Omit<V, T[keyof T]> & { [K in keyof T]: V[T[K]] } { // .. } const result = reobjectKeys(query, rename); // 以下应该能正常提示key和type result.age; result.type; result.teacher_name;
试试这个是否符合你的需求