'How to compare two class objects - typescript

I want to compare two class objects in typescript to see which properties have changed. I have tried this but get an error:

Element implicitly has an 'any' type because index expression is not of type 'number'.(7015)

class MyObject {
    prop1: string|undefined;
    prop2: string|undefined;
    prop3: string|undefined;

    static getValue(): number{
        return 1;
    }
}

let obj1: MyObject = {
    prop1: "prop1Val",
    prop2: "prop2Val",
    prop3: "prop3Val"
}

let obj2: MyObject = {
    prop1: "prop1Val",
    prop2: "prop2Changed",
    prop3: "prop3Changed"
}

let compObj1 = JSON.stringify(obj1);
let compObj2 = JSON.stringify(obj2);

let difference = Object.entries(compObj1).filter(([k, v], i) => compObj1[k] !== compObj2[k]);

In this example I want to try and return something like: [{"prop2": "prop2Changed"}, {"prop3": "prop3Changed"}]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source