Skip to content

Commit b5998d9

Browse files
Merge pull request #26625 from ajafff/revert-destructuring-private-computed-name
Revert #26360: Don't error on destructure of private property with computed property syntax
2 parents 0043ba1 + bedf776 commit b5998d9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24250,7 +24250,7 @@ namespace ts {
2425024250
if (nameText) {
2425124251
const property = getPropertyOfType(parentType!, nameText)!; // TODO: GH#18217
2425224252
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
24253-
if (parent.initializer && property && !isComputedPropertyName(name)) {
24253+
if (parent.initializer && property) {
2425424254
checkPropertyAccessibility(parent, parent.initializer.kind === SyntaxKind.SuperKeyword, parentType!, property);
2425524255
}
2425624256
}

tests/baselines/reference/destructureComputedProperty.errors.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
tests/cases/compiler/destructureComputedProperty.ts(7,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
2+
tests/cases/compiler/destructureComputedProperty.ts(8,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
23
tests/cases/compiler/destructureComputedProperty.ts(10,7): error TS2341: Property 'p' is private and only accessible within class 'C'.
34

45

5-
==== tests/cases/compiler/destructureComputedProperty.ts (2 errors) ====
6+
==== tests/cases/compiler/destructureComputedProperty.ts (3 errors) ====
67
declare const ab: { n: number } | { n: string };
78
const nameN = "n";
89
const { [nameN]: n } = ab;
@@ -13,6 +14,8 @@ tests/cases/compiler/destructureComputedProperty.ts(10,7): error TS2341: Propert
1314
~~~~~~~~~~~
1415
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
1516
const { ["p"]: p1 } = new C();
17+
~~~~~~~~~~~~~
18+
!!! error TS2341: Property 'p' is private and only accessible within class 'C'.
1619
const { [nameP]: p2 } = new C();
1720
const { p: p3 } = new C();
1821
~~~~~~~~~

0 commit comments

Comments
 (0)