mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 10:40:34 -05:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user