Skip to content

Commit 14f6bf2

Browse files
authored
Merge pull request #15518 from vkurchatkin/empty-property
Allow indexed access to empty property
2 parents 7ac22c4 + d45d289 commit 14f6bf2

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7257,7 +7257,7 @@ namespace ts {
72577257
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
72587258
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
72597259
undefined;
7260-
if (propName) {
7260+
if (propName !== undefined) {
72617261
const prop = getPropertyOfType(objectType, propName);
72627262
if (prop) {
72637263
if (accessExpression) {

tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(1,9): error TS7017: E
44
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (1 errors) ====
55
var x = {}["hello"];
66
~~~~~~~~~~~
7-
!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature.
7+
!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature.
8+
var y: string = { '': 'foo' }[''];
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//// [noImplicitAnyStringIndexerOnObject.ts]
2-
var x = {}["hello"];
2+
var x = {}["hello"];
3+
var y: string = { '': 'foo' }[''];
34

45
//// [noImplicitAnyStringIndexerOnObject.js]
56
var x = {}["hello"];
7+
var y = { '': 'foo' }[''];
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// @noimplicitany: true
22

3-
var x = {}["hello"];
3+
var x = {}["hello"];
4+
var y: string = { '': 'foo' }[''];

0 commit comments

Comments
 (0)