I am working with the following content structure:
interface User {
email: string;
name: string;
}
...and have created a react component as shown below:
const MyComponent = <Values extends object>({ values }: { values: Values }) => {
console.log(values);
return <div></div>
}
Suppose I use MyComponent
with the User
interface, allowing me to pass in values
. The question is: how can I alter the JSON object being passed so that any properties not found in the generic type Values
are removed? In other words, if I provide the object:
{
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0ddd1d9dcf0d5c8d1ddc0dcd59edfc2d7">[email protected]</a>',
name: 'Some name',
foo: 'bar'
}
I want the console.log(values)
statement in the component to display the object without foo: 'bar'
.