diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56a36f658d719..d4d0ceb61e12e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27000,7 +27000,8 @@ namespace ts { const links = getNodeLinks(node.expression); if (!links.resolvedType) { if ((isTypeLiteralNode(node.parent.parent) || isClassLike(node.parent.parent) || isInterfaceDeclaration(node.parent.parent)) - && isBinaryExpression(node.expression) && node.expression.operatorToken.kind === SyntaxKind.InKeyword) { + && isBinaryExpression(node.expression) && node.expression.operatorToken.kind === SyntaxKind.InKeyword + && node.parent.kind !== SyntaxKind.GetAccessor && node.parent.kind !== SyntaxKind.SetAccessor) { return links.resolvedType = errorType; } links.resolvedType = checkExpression(node.expression); diff --git a/tests/baselines/reference/noMappedGetSet.errors.txt b/tests/baselines/reference/noMappedGetSet.errors.txt new file mode 100644 index 0000000000000..55f3b3243584a --- /dev/null +++ b/tests/baselines/reference/noMappedGetSet.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/noMappedGetSet.ts(2,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/noMappedGetSet.ts(2,10): error TS2304: Cannot find name 'K'. +tests/cases/compiler/noMappedGetSet.ts(2,15): error TS2304: Cannot find name 'WAT'. + + +==== tests/cases/compiler/noMappedGetSet.ts (3 errors) ==== + type OH_NO = { + get [K in WAT](): string + ~~~~~~~~~~ +!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + ~ +!!! error TS2304: Cannot find name 'K'. + ~~~ +!!! error TS2304: Cannot find name 'WAT'. + }; + \ No newline at end of file diff --git a/tests/baselines/reference/noMappedGetSet.js b/tests/baselines/reference/noMappedGetSet.js new file mode 100644 index 0000000000000..16fdaf924b96f --- /dev/null +++ b/tests/baselines/reference/noMappedGetSet.js @@ -0,0 +1,7 @@ +//// [noMappedGetSet.ts] +type OH_NO = { + get [K in WAT](): string +}; + + +//// [noMappedGetSet.js] diff --git a/tests/baselines/reference/noMappedGetSet.symbols b/tests/baselines/reference/noMappedGetSet.symbols new file mode 100644 index 0000000000000..520eb2f8b4b5a --- /dev/null +++ b/tests/baselines/reference/noMappedGetSet.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/noMappedGetSet.ts === +type OH_NO = { +>OH_NO : Symbol(OH_NO, Decl(noMappedGetSet.ts, 0, 0)) + + get [K in WAT](): string +>[K in WAT] : Symbol([K in WAT], Decl(noMappedGetSet.ts, 0, 14)) + +}; + diff --git a/tests/baselines/reference/noMappedGetSet.types b/tests/baselines/reference/noMappedGetSet.types new file mode 100644 index 0000000000000..1f46980e4b1eb --- /dev/null +++ b/tests/baselines/reference/noMappedGetSet.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/noMappedGetSet.ts === +type OH_NO = { +>OH_NO : OH_NO + + get [K in WAT](): string +>[K in WAT] : string +>K in WAT : boolean +>K : any +>WAT : any + +}; + diff --git a/tests/cases/compiler/noMappedGetSet.ts b/tests/cases/compiler/noMappedGetSet.ts new file mode 100644 index 0000000000000..c48fb74c3b0e3 --- /dev/null +++ b/tests/cases/compiler/noMappedGetSet.ts @@ -0,0 +1,3 @@ +type OH_NO = { + get [K in WAT](): string +};