In typescript, I have an object of type any
that needs to be reshaped to align with a specific interface.
I am looking for a solution to create a new object that removes any properties not defined in the interface and adds any missing properties.
An example code snippet is provided below:
interface ImyInterface {
a: string;
b: string;
c?:string;
};
let myObject = {
a: "myString",
d: "other value"
};
My query is: Is there a method to filter and convert the myObject
so that it adheres to the structure outlined in the ImyInterface
interface, resulting in:
console.log (JSON.stringify(objectA));
> {a: 'myString', b: null}