Skip to content

Commit d67fe13

Browse files
committed
Don't ignore index signatures in this type constraints
1 parent d484163 commit d67fe13

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,7 +3563,7 @@ namespace ts {
35633563
context.approximateLength += 6;
35643564
return createKeywordTypeNode(SyntaxKind.ObjectKeyword);
35653565
}
3566-
if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
3566+
if (isThisTypeParameter(type)) {
35673567
if (context.flags & NodeBuilderFlags.InObjectTypeLiteral) {
35683568
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowThisInObjectLiteral)) {
35693569
context.encounteredError = true;
@@ -10193,6 +10193,10 @@ namespace ts {
1019310193
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index);
1019410194
}
1019510195

10196+
function isThisTypeParameter(type: Type): boolean {
10197+
return !!(type.flags & TypeFlags.TypeParameter && (<TypeParameter>type).isThisType);
10198+
}
10199+
1019610200
function getSimplifiedType(type: Type, writing: boolean): Type {
1019710201
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(<IndexedAccessType>type, writing) :
1019810202
type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(<ConditionalType>type, writing) :
@@ -16772,7 +16776,7 @@ namespace ts {
1677216776
}
1677316777

1677416778
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
16775-
if ((type.flags & (TypeFlags.Union | TypeFlags.Object)) || (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType)) {
16779+
if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
1677616780
const propName = escapeLeadingUnderscores(literal.text);
1677716781
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
1677816782
}
@@ -20092,7 +20096,7 @@ namespace ts {
2009220096
return anyType;
2009320097
}
2009420098
if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
20095-
reportNonexistentProperty(right, leftType.flags & TypeFlags.TypeParameter && (leftType as TypeParameter).isThisType ? apparentType : leftType);
20099+
reportNonexistentProperty(right, isThisTypeParameter(leftType) ? apparentType : leftType);
2009620100
}
2009720101
return errorType;
2009820102
}
@@ -20496,7 +20500,7 @@ namespace ts {
2049620500

2049720501
const effectiveIndexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : indexType;
2049820502
const accessFlags = isAssignmentTarget(node) ?
20499-
AccessFlags.Writing | (isGenericObjectType(objectType) ? AccessFlags.NoIndexSignatures : 0) :
20503+
AccessFlags.Writing | (isGenericObjectType(objectType) && !isThisTypeParameter(objectType) ? AccessFlags.NoIndexSignatures : 0) :
2050020504
AccessFlags.None;
2050120505
const indexedAccessType = getIndexedAccessTypeOrUndefined(objectType, effectiveIndexType, node, accessFlags) || errorType;
2050220506
return checkIndexedAccessIndexType(indexedAccessType, node);

0 commit comments

Comments
 (0)