mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Don't ignore index signatures in this type constraints
This commit is contained in:
parent
d484163d0f
commit
d67fe13e30
@ -3563,7 +3563,7 @@ namespace ts {
|
||||
context.approximateLength += 6;
|
||||
return createKeywordTypeNode(SyntaxKind.ObjectKeyword);
|
||||
}
|
||||
if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
|
||||
if (isThisTypeParameter(type)) {
|
||||
if (context.flags & NodeBuilderFlags.InObjectTypeLiteral) {
|
||||
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowThisInObjectLiteral)) {
|
||||
context.encounteredError = true;
|
||||
@ -10193,6 +10193,10 @@ namespace ts {
|
||||
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index);
|
||||
}
|
||||
|
||||
function isThisTypeParameter(type: Type): boolean {
|
||||
return !!(type.flags & TypeFlags.TypeParameter && (<TypeParameter>type).isThisType);
|
||||
}
|
||||
|
||||
function getSimplifiedType(type: Type, writing: boolean): Type {
|
||||
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(<IndexedAccessType>type, writing) :
|
||||
type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(<ConditionalType>type, writing) :
|
||||
@ -16772,7 +16776,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
|
||||
if ((type.flags & (TypeFlags.Union | TypeFlags.Object)) || (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType)) {
|
||||
if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) {
|
||||
const propName = escapeLeadingUnderscores(literal.text);
|
||||
return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue));
|
||||
}
|
||||
@ -20092,7 +20096,7 @@ namespace ts {
|
||||
return anyType;
|
||||
}
|
||||
if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
|
||||
reportNonexistentProperty(right, leftType.flags & TypeFlags.TypeParameter && (leftType as TypeParameter).isThisType ? apparentType : leftType);
|
||||
reportNonexistentProperty(right, isThisTypeParameter(leftType) ? apparentType : leftType);
|
||||
}
|
||||
return errorType;
|
||||
}
|
||||
@ -20496,7 +20500,7 @@ namespace ts {
|
||||
|
||||
const effectiveIndexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : indexType;
|
||||
const accessFlags = isAssignmentTarget(node) ?
|
||||
AccessFlags.Writing | (isGenericObjectType(objectType) ? AccessFlags.NoIndexSignatures : 0) :
|
||||
AccessFlags.Writing | (isGenericObjectType(objectType) && !isThisTypeParameter(objectType) ? AccessFlags.NoIndexSignatures : 0) :
|
||||
AccessFlags.None;
|
||||
const indexedAccessType = getIndexedAccessTypeOrUndefined(objectType, effectiveIndexType, node, accessFlags) || errorType;
|
||||
return checkIndexedAccessIndexType(indexedAccessType, node);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user