Lets say I have a type/interface like this:
interface MyInterface {
memberInTheInterface?: string;
// ... more members
}
and an object that looks like this:
const myObject = {
memberInTheInterface: "foo",
// ... more members that are in the interface
memberNotInTheInterface: "bar"
// ... more members that are not in the interface
}
Now I want to get a new object with all the members of myObject except those that are in the type/interface, such that in the end I have an object like this:
{
memberNotInTheInterface: "bar"
// ... other members not in the interface
}
I know that you can use the spread operator to exclude certain members from an object like this:
const { memberInTheInterface, ...myNewObject } = myObject;
However, I do not want to statically type out all the member names, and instead use all (including optional) members of a type dynamically. Is this possible and if so how?
I tried to find an answer in the TypeScript manual, via Google and obviously here, but with no avail. Is there some keyword or phrase that would have brought me to an existing answer?