Merge pull request #10009 from Microsoft/null-undefined-allowed-as-index-expressions

`Null` and `undefined` are allowed as index expressions
This commit is contained in:
Nathan Shively-Sanders
2016-08-16 15:46:42 -07:00
committed by GitHub
8 changed files with 199 additions and 2 deletions

View File

@@ -10842,10 +10842,11 @@ namespace ts {
}
// Check for compatible indexer types.
if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol)) {
const allowedNullableFlags = strictNullChecks ? 0 : TypeFlags.Nullable;
if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbol | allowedNullableFlags)) {
// Try to use a number indexer.
if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike) || isForInVariableForNumericPropertyNames(node.argumentExpression)) {
if (isTypeAnyOrAllConstituentTypesHaveKind(indexType, TypeFlags.NumberLike | allowedNullableFlags) || isForInVariableForNumericPropertyNames(node.argumentExpression)) {
const numberIndexInfo = getIndexInfoOfType(objectType, IndexKind.Number);
if (numberIndexInfo) {
getNodeLinks(node).resolvedIndexInfo = numberIndexInfo;