Closed
Description
TypeScript Version: 4.1.2
Search Terms:
(arg1:keyof T, arg2:T[typeof arg1])
Code
type MyType = {
foo:string
}
class MyClass<T extends MyType = MyType> {
/* this is the failing function */
callMe = (arg1:keyof T, arg12:T[typeof arg1]) => null;
/* callMe not working when calling inside the class */
testInsideClass = () => {
this.callMe('foo', 'not-working'); // <-- Compiler error on second argument
}
}
/* callMe working when calling from an instance of the class */
const classInstance = new MyClass<MyType>();
classInstance.callMe('foo', 'working'); // <-- No compiler error here
Expected behavior:
Able to call class function callMe from within the class since T extends MyType
Actual behavior:
Compiler says argument of type 'string' is not assignable to parameter of type 'T[keyof T]'.ts(2345)
Playground Link:
Related Issues:
Maybe #39945 is related