Skip to content

Commit 1b8c68d

Browse files
Revert "Add check for delete expression must be optional (#37921)" (#38154)
This reverts commit 39beb1d.
1 parent 84c83da commit 1b8c68d

14 files changed

+4
-856
lines changed

src/compiler/checker.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -27682,23 +27682,12 @@ namespace ts {
2768227682
}
2768327683
const links = getNodeLinks(expr);
2768427684
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
27685-
if (symbol) {
27686-
if (isReadonlySymbol(symbol)) {
27687-
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
27688-
}
27689-
27690-
checkDeleteExpressionMustBeOptional(expr, getTypeOfSymbol(symbol));
27685+
if (symbol && isReadonlySymbol(symbol)) {
27686+
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
2769127687
}
2769227688
return booleanType;
2769327689
}
2769427690

27695-
function checkDeleteExpressionMustBeOptional(expr: AccessExpression, type: Type) {
27696-
const AnyOrUnknownOrNeverFlags = TypeFlags.AnyOrUnknown | TypeFlags.Never;
27697-
if (strictNullChecks && !(type.flags & AnyOrUnknownOrNeverFlags) && !(getFalsyFlags(type) & TypeFlags.Undefined)) {
27698-
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_optional);
27699-
}
27700-
}
27701-
2770227691
function checkTypeOfExpression(node: TypeOfExpression): Type {
2770327692
checkExpression(node.expression);
2770427693
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)