Skip to content

Commit 2172e19

Browse files
Correctly check computed property names in type-space get/set accessors (#47156)
* Add test that should fail * Make it fail Fixes #47146 * Baselines
1 parent 46e7ab4 commit 2172e19

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27089,7 +27089,8 @@ namespace ts {
2708927089
const links = getNodeLinks(node.expression);
2709027090
if (!links.resolvedType) {
2709127091
if ((isTypeLiteralNode(node.parent.parent) || isClassLike(node.parent.parent) || isInterfaceDeclaration(node.parent.parent))
27092-
&& isBinaryExpression(node.expression) && node.expression.operatorToken.kind === SyntaxKind.InKeyword) {
27092+
&& isBinaryExpression(node.expression) && node.expression.operatorToken.kind === SyntaxKind.InKeyword
27093+
&& node.parent.kind !== SyntaxKind.GetAccessor && node.parent.kind !== SyntaxKind.SetAccessor) {
2709327094
return links.resolvedType = errorType;
2709427095
}
2709527096
links.resolvedType = checkExpression(node.expression);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/noMappedGetSet.ts(2,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
2+
tests/cases/compiler/noMappedGetSet.ts(2,10): error TS2304: Cannot find name 'K'.
3+
tests/cases/compiler/noMappedGetSet.ts(2,15): error TS2304: Cannot find name 'WAT'.
4+
5+
6+
==== tests/cases/compiler/noMappedGetSet.ts (3 errors) ====
7+
type OH_NO = {
8+
get [K in WAT](): string
9+
~~~~~~~~~~
10+
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
11+
~
12+
!!! error TS2304: Cannot find name 'K'.
13+
~~~
14+
!!! error TS2304: Cannot find name 'WAT'.
15+
};
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [noMappedGetSet.ts]
2+
type OH_NO = {
3+
get [K in WAT](): string
4+
};
5+
6+
7+
//// [noMappedGetSet.js]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/noMappedGetSet.ts ===
2+
type OH_NO = {
3+
>OH_NO : Symbol(OH_NO, Decl(noMappedGetSet.ts, 0, 0))
4+
5+
get [K in WAT](): string
6+
>[K in WAT] : Symbol([K in WAT], Decl(noMappedGetSet.ts, 0, 14))
7+
8+
};
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/noMappedGetSet.ts ===
2+
type OH_NO = {
3+
>OH_NO : OH_NO
4+
5+
get [K in WAT](): string
6+
>[K in WAT] : string
7+
>K in WAT : boolean
8+
>K : any
9+
>WAT : any
10+
11+
};
12+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type OH_NO = {
2+
get [K in WAT](): string
3+
};

0 commit comments

Comments
 (0)