diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a4d73056e0995..616fff013ac61 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2744,7 +2744,10 @@ namespace ts { break; case SyntaxKind.SourceFile: // this.property = assignment in a source file -- declare symbol in exports for a module, in locals for a script - if ((thisContainer as SourceFile).commonJsModuleIndicator) { + if (hasDynamicName(node)) { + break; + } + else if ((thisContainer as SourceFile).commonJsModuleIndicator) { declareSymbol(thisContainer.symbol.exports!, thisContainer.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None); } else { diff --git a/tests/baselines/reference/thisPropertyAssignmentComputed.errors.txt b/tests/baselines/reference/thisPropertyAssignmentComputed.errors.txt new file mode 100644 index 0000000000000..e38c2c1754643 --- /dev/null +++ b/tests/baselines/reference/thisPropertyAssignmentComputed.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js(1,1): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof globalThis'. + No index signature with a parameter of type 'string' was found on type 'typeof globalThis'. + + +==== tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js (1 errors) ==== + this["a" + "b"] = 0 + ~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof globalThis'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type 'typeof globalThis'. + \ No newline at end of file diff --git a/tests/baselines/reference/thisPropertyAssignmentComputed.symbols b/tests/baselines/reference/thisPropertyAssignmentComputed.symbols new file mode 100644 index 0000000000000..72f1a5188e96c --- /dev/null +++ b/tests/baselines/reference/thisPropertyAssignmentComputed.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js === +this["a" + "b"] = 0 +>this : Symbol(globalThis) + diff --git a/tests/baselines/reference/thisPropertyAssignmentComputed.types b/tests/baselines/reference/thisPropertyAssignmentComputed.types new file mode 100644 index 0000000000000..324518c76c054 --- /dev/null +++ b/tests/baselines/reference/thisPropertyAssignmentComputed.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js === +this["a" + "b"] = 0 +>this["a" + "b"] = 0 : 0 +>this["a" + "b"] : any +>this : typeof globalThis +>"a" + "b" : string +>"a" : "a" +>"b" : "b" +>0 : 0 + diff --git a/tests/cases/conformance/salsa/thisPropertyAssignmentComputed.ts b/tests/cases/conformance/salsa/thisPropertyAssignmentComputed.ts new file mode 100644 index 0000000000000..37db10ca3b2a2 --- /dev/null +++ b/tests/cases/conformance/salsa/thisPropertyAssignmentComputed.ts @@ -0,0 +1,6 @@ +// @allowjs: true +// @checkjs: true +// @noemit: true +// @strict: true +// @filename: thisPropertyAssignmentComputed.js +this["a" + "b"] = 0