TypeScript 错误“'删除'运算符的操作数必须是可选的”背后的逻辑是什么?
2022-08-30 04:17:31
这是类型脚本代码中出现的新错误。
我无法意识到它
背后的逻辑 文档
/*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.
}