interface person{ name: string id: number sex: boolean }
func1<T extends keyof person,K extends person>( a: T, b: K[T] ){ }
简化一下
func1<T extends keyof person>( a: T, b: person[T] ){ }
调用方法
changeName(){ this.func1("name", "2") this.func1("name", 2) // 报错 this.func1("id", "2") // 报错 this.func1("id", 2) this.func1("sex", true) }
标签:func1,name,TS,sex,参数,类型,报错,id From: https://www.cnblogs.com/sexintercourse/p/17764239.html