From aa6f3a388a95f8cde519741c8f634cef04b68fbf Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh <ryanca@microsoft.com> Date: Tue, 14 Dec 2021 21:34:26 -0800 Subject: [PATCH 1/3] Add test that should fail --- tests/baselines/reference/noMappedGetSet.js | 7 +++++++ tests/baselines/reference/noMappedGetSet.symbols | 9 +++++++++ tests/baselines/reference/noMappedGetSet.types | 12 ++++++++++++ tests/cases/compiler/noMappedGetSet.ts | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 tests/baselines/reference/noMappedGetSet.js create mode 100644 tests/baselines/reference/noMappedGetSet.symbols create mode 100644 tests/baselines/reference/noMappedGetSet.types create mode 100644 tests/cases/compiler/noMappedGetSet.ts 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..419061bd947ce --- /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 : error +>WAT : error + +}; + 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 +}; From 53170d9801d660bfc556644553140a78098543f5 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh <ryanca@microsoft.com> Date: Tue, 14 Dec 2021 21:35:36 -0800 Subject: [PATCH 2/3] Make it fail Fixes #47146 --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); From bee1a0d4ef078579a4e7281c918df1e148f710bd Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh <ryanca@microsoft.com> Date: Tue, 14 Dec 2021 22:11:28 -0800 Subject: [PATCH 3/3] Baselines --- .../reference/noMappedGetSet.errors.txt | 16 ++++++++++++++++ tests/baselines/reference/noMappedGetSet.types | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/noMappedGetSet.errors.txt 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.types b/tests/baselines/reference/noMappedGetSet.types index 419061bd947ce..1f46980e4b1eb 100644 --- a/tests/baselines/reference/noMappedGetSet.types +++ b/tests/baselines/reference/noMappedGetSet.types @@ -5,8 +5,8 @@ type OH_NO = { get [K in WAT](): string >[K in WAT] : string >K in WAT : boolean ->K : error ->WAT : error +>K : any +>WAT : any };