After researching how to delete a property from an object, I came across this helpful thread on Stack Overflow. The recommended method is to use the delete
keyword. So, I attempted it like this:
const eventData = {...myEvent};
delete eventData.coordinate;
However, I encountered an error which looked like this:
https://i.sstatic.net/uDF2g.png
The operand of a 'delete' operator must be optional.ts(2790)
Further research led me to another discussion on Stack Overflow, where it was suggested that changing the tsconfig.json file could resolve this issue:
{
"compilerOptions": {
...
"strictNullChecks": false,
}
...
}
However, implementing this change would mean sacrificing null checking. So, my question remains: how can I delete a property from an object in Typescript without encountering the 'operand of a 'delete' operator must be optional' error?