TypeScript 泛型: 获取 key 对应的 类型 作者: Chuwen 时间: 2022-02-07 分类: TypeScript 相关链接参考: - https://stackoverflow.com/questions/49285864/is-there-a-valueof-similar-to-keyof-in-typescript - https://segmentfault.com/q/1010000040514337 - https://segmentfault.com/a/1190000023800536 实例: ```ts export type Student = { name: string age: number birth: { year: number month: number } } export const student: Student | null = null export function setStudentInfo(key: K, val: Student[K]) { student && (student.hasOwnProperty(key) = val) } ``` 标签: TypeScript, 泛型
该网站无法添加新的更新,存不了了
你是哪个用户 哪个网站