what is the logic behind error - the operand of a 'delete' operator must be optional typescript 4.0
The logic behind of this, is that you need to implement your interface with an optional property like this:
interface Thing {
prop?: string;
}
function f(x: Thing) {
delete x.prop;
}
So the interface's contract won't be broken.
I am not able to realize the logic behind it
The logic as I understand is the following:
Interface Thing
is a contract asking to have a (non-null, non-undefined) string prop
.
If one removes the property, then the contract is not implemented anymore.
I'm actually surprised that this was not causing error in earlier versions of TypeScript.