mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Add check for delete expression must be optional (#37921)
* Add check for delete expression must be optional * Add more tests
This commit is contained in:
@@ -27583,12 +27583,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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user