Skip to content

Commit 399cebb

Browse files
Revert "Add check for delete expression must be optional (#37921)"
This reverts commit 39beb1d.
1 parent d7e437a commit 399cebb

14 files changed

+4
-856
lines changed

src/compiler/checker.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -27583,23 +27583,12 @@ namespace ts {
2758327583
}
2758427584
const links = getNodeLinks(expr);
2758527585
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
27586-
if (symbol) {
27587-
if (isReadonlySymbol(symbol)) {
27588-
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
27589-
}
27590-
27591-
checkDeleteExpressionMustBeOptional(expr, getTypeOfSymbol(symbol));
27586+
if (symbol && isReadonlySymbol(symbol)) {
27587+
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
2759227588
}
2759327589
return booleanType;
2759427590
}
2759527591

27596-
function checkDeleteExpressionMustBeOptional(expr: AccessExpression, type: Type) {
27597-
const AnyOrUnknownOrNeverFlags = TypeFlags.AnyOrUnknown | TypeFlags.Never;
27598-
if (strictNullChecks && !(type.flags & AnyOrUnknownOrNeverFlags) && !(getFalsyFlags(type) & TypeFlags.Undefined)) {
27599-
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_optional);
27600-
}
27601-
}
27602-
2760327592
function checkTypeOfExpression(node: TypeOfExpression): Type {
2760427593
checkExpression(node.expression);
2760527594
return typeofType;

src/compiler/diagnosticMessages.json

-4
Original file line numberDiff line numberDiff line change
@@ -2963,10 +2963,6 @@
29632963
"category": "Error",
29642964
"code": 2789
29652965
},
2966-
"The operand of a 'delete' operator must be optional.": {
2967-
"category": "Error",
2968-
"code": 2790
2969-
},
29702966

29712967
"Import declaration '{0}' is using private name '{1}'.": {
29722968
"category": "Error",

tests/baselines/reference/controlFlowDeleteOperator.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(10,12): error TS2790: The operand of a 'delete' operator must be optional.
21
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(14,12): error TS2703: The operand of a 'delete' operator must be a property reference.
32

43

5-
==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (2 errors) ====
4+
==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (1 errors) ====
65
function f() {
76
let x: { a?: number | string, b: number | string } = { b: 1 };
87
x.a;
@@ -13,8 +12,6 @@ tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(14,12): error T
1312
x.b;
1413
delete x.a;
1514
delete x.b;
16-
~~~
17-
!!! error TS2790: The operand of a 'delete' operator must be optional.
1815
x.a;
1916
x.b;
2017
x;

tests/baselines/reference/deleteChain.errors.txt

-66
This file was deleted.

tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).errors.txt

-46
This file was deleted.

tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).js

-57
This file was deleted.

tests/baselines/reference/deleteExpressionMustBeOptional(strict=false).symbols

-118
This file was deleted.

0 commit comments

Comments
 (0)