作者:xie392地址:https://v.douyin.com/ie9Tnc5T/更新时间:2024-12-21
1const cat = {2name: 'Kitty',3age: 24}56// 泛型约束 K 必须是对象的某个属性7function handler<T extends object, K extends keyof T>(obj:T,prop:K) {}89// handler(cat,'s') // error10handler(cat,'name') // ok