Skip to content

Commit dad5736

Browse files
ahejlsbergmhegazy
authored andcommitted
Support apparent types for T[K] indexed access types
1 parent c1d9b19 commit dad5736

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4666,13 +4666,22 @@ namespace ts {
46664666
return type.resolvedApparentType;
46674667
}
46684668

4669+
/**
4670+
* The apparent type of an indexed access T[K] is the type of T's string index signature, if any.
4671+
*/
4672+
function getApparentTypeOfIndexedAccess(type: IndexedAccessType) {
4673+
return getIndexTypeOfType(getApparentType(type.objectType), IndexKind.String) || type;
4674+
}
4675+
46694676
/**
46704677
* For a type parameter, return the base constraint of the type parameter. For the string, number,
46714678
* boolean, and symbol primitive types, return the corresponding object types. Otherwise return the
46724679
* type itself. Note that the apparent type of a union type is the union type itself.
46734680
*/
46744681
function getApparentType(type: Type): Type {
4675-
const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(<TypeParameter>type) : type;
4682+
const t = type.flags & TypeFlags.TypeParameter ? getApparentTypeOfTypeParameter(<TypeParameter>type) :
4683+
type.flags & TypeFlags.IndexedAccess ? getApparentTypeOfIndexedAccess(<IndexedAccessType>type) :
4684+
type;
46764685
return t.flags & TypeFlags.StringLike ? globalStringType :
46774686
t.flags & TypeFlags.NumberLike ? globalNumberType :
46784687
t.flags & TypeFlags.BooleanLike ? globalBooleanType :

0 commit comments

Comments
 (0)