Indexed access any[K] has type any

This commit is contained in:
Anders Hejlsberg
2016-12-04 07:43:10 -08:00
parent b7e8a6d1f1
commit c52eb6cef3

View File

@@ -6033,6 +6033,9 @@ namespace ts {
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
if (maybeTypeOfKind(indexType, TypeFlags.TypeVariable | TypeFlags.Index) || isGenericMappedType(objectType)) {
if (objectType.flags & TypeFlags.Any) {
return objectType;
}
// If the index type is generic or if the object type is a mapped type with a generic constraint,
// we are performing a higher-order index access where we cannot meaningfully access the properties
// of the object type. In those cases, we first check that the index type is assignable to 'keyof T'