Revert "Revert "Add check for delete expression must be optional (#37921)" (#38154)" (#38173)

This reverts commit 1b8c68d746.
This commit is contained in:
Daniel Rosenwasser
2020-04-27 13:23:45 -07:00
committed by GitHub
parent 468ca9f870
commit 6a6c83cf9a
14 changed files with 856 additions and 4 deletions

View File

@@ -27682,12 +27682,23 @@ namespace ts {
}
const links = getNodeLinks(expr);
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
if (symbol && isReadonlySymbol(symbol)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
if (symbol) {
if (isReadonlySymbol(symbol)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
}
checkDeleteExpressionMustBeOptional(expr, getTypeOfSymbol(symbol));
}
return booleanType;
}
function checkDeleteExpressionMustBeOptional(expr: AccessExpression, type: Type) {
const AnyOrUnknownOrNeverFlags = TypeFlags.AnyOrUnknown | TypeFlags.Never;
if (strictNullChecks && !(type.flags & AnyOrUnknownOrNeverFlags) && !(getFalsyFlags(type) & TypeFlags.Undefined)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_optional);
}
}
function checkTypeOfExpression(node: TypeOfExpression): Type {
checkExpression(node.expression);
return typeofType;

View File

@@ -2963,6 +2963,10 @@
"category": "Error",
"code": 2789
},
"The operand of a 'delete' operator must be optional.": {
"category": "Error",
"code": 2790
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",