做其中任何一项都有什么实质性的区别吗?
delete a.x;
Run Code Online (Sandbox Code Playgroud)
VS
a.x = undefined;
Run Code Online (Sandbox Code Playgroud)
哪里
a = {
x: 'boo'
};
Run Code Online (Sandbox Code Playgroud)
可以说它们是等价的吗?
(我没有考虑像"V8喜欢不用delete得更好"之类的东西)
这是打字稿代码中出现的新错误。
我无法实现其背后的逻辑
文档
/*When using the delete operator in strictNullChecks,
the operand must now be any, unknown, never, or be optional
(in that it contains undefined in the type). Otherwise, use of the delete operator is an error.*/
interface Thing {
prop: string;
}
function f(x: Thing) {
delete x.prop; // throws error = The operand of a 'delete' operator must be optional.
}
Run Code Online (Sandbox Code Playgroud)