Consider this code snippet:
interface IAssociativeArray {
[key: string]: any;
}
function Modify<T extends IAssociativeArray>(obj: T) {
obj.someProperty = "newValue";
}
function Modify2(obj: IAssociativeArray) {
obj.someProperty = "newValue";
}
Modify
results in the error message: Property 'someProperty' does not exist on type 'T'.ts(2339). On the other hand, Modify2
works without any errors. What could be causing this difference?
Note: This is tested using Typescript version 3.6.3 and seems to function correctly in versions prior to 3.5.1.