Could someone explains why in the example code below typescript gives the error message "const key: string Argument of type 'string' is not assignable to parameter of type 'keyof Condition"
interface Condition {
GOOD: 'GOOD';
BAD: 'BAD';
NONE: 'NONE';
}
const ObjWithAllCondition: Condition = {
GOOD: 'GOOD',
BAD: 'BAD',
NONE: 'NONE',
};
interface Result {
condition: keyof Condition;
count: number;
}
const getKeyValue = <T extends Condition, K extends keyof T>(obj: T, key: K) => obj[key];
const getResult = (): Result[] => {
const result = [];
for (const key in ObjWithAllCondition) {
result.push({
condition: getKeyValue(ObjWithAllCondition, key), // this is error
count: 1,
});
}
return result;
};