"image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241128/a8c00e41e42519adb64f7debdffe2be3.png)
typescript,函数如何根据传入的key,返回对象对应的这些key?比如: const obj = { name: 'Marcelo', age: 27, role: ['admin'] }; type ObjType = { [key in keyof typeof obj]: typeof obj[key] } const getAttr = >(...attribute: KS): T[KS] => { const result = {}; for (const attr of attribute) { result[attr] = obj[attr]; } return result; }; const attr = getAttr('age', 'name'); 现在这个写法肯定不对,变量attr的推断是unknown,如何写函数getAttr的返回定义,才能让变量attr的推断为{age:number, name:string },就是函数传入了哪些key,就只返回这些key的推断
java 中 , 还有 "int.class" 这种写法 ? int 不是基本类型吗 ??