Allow indexed access to empty property

Fixes: https://github.com/Microsoft/TypeScript/issues/15209
This commit is contained in:
Vladimir Kurchatkin 2017-05-02 01:39:02 +03:00
parent 88f9a978dd
commit d45d289f36
4 changed files with 8 additions and 4 deletions

View File

@ -7257,7 +7257,7 @@ namespace ts {
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
undefined;
if (propName) {
if (propName !== undefined) {
const prop = getPropertyOfType(objectType, propName);
if (prop) {
if (accessExpression) {

View File

@ -4,4 +4,5 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(1,9): error TS7017: E
==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (1 errors) ====
var x = {}["hello"];
~~~~~~~~~~~
!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature.
!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature.
var y: string = { '': 'foo' }[''];

View File

@ -1,5 +1,7 @@
//// [noImplicitAnyStringIndexerOnObject.ts]
var x = {}["hello"];
var x = {}["hello"];
var y: string = { '': 'foo' }[''];
//// [noImplicitAnyStringIndexerOnObject.js]
var x = {}["hello"];
var y = { '': 'foo' }[''];

View File

@ -1,3 +1,4 @@
// @noimplicitany: true
var x = {}["hello"];
var x = {}["hello"];
var y: string = { '': 'foo' }[''];