Is there a workaround for this issue? I am working with an interface, IFoo, and an array of data IFoo[]. My goal is to map this data and modify a single property. It should look something like this
const mapper = (foos: IFoo[]): IFoo[] => {
return foos.map((f) => {
return {
...f,
prop4: 42
};
});
};
The catch is that "prop4" is not part of IFoo, but the compiler doesn't raise an error because I used the spread operator "...f" which sets all necessary props. However, I mistakenly intended to change "prop3" and missed the error.
Explicitly setting all properties is not ideal as it's time-consuming and prone to errors if a new possibly undefined prop is added to IFoo.
You can review the complete example at codesandbox.io