Merge pull request #15518 from vkurchatkin/empty-property

Allow indexed access to empty property
This commit is contained in:
Mohamed Hegazy 2017-05-01 16:37:02 -07:00 committed by GitHub
commit 14f6bf2244
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' }[''];