getConstraintDeclaration gets the first declaration with a constraint, rather than just the first declaration

This commit is contained in:
Wesley Wigham
2019-09-13 16:42:26 -07:00
parent 038d95144d
commit 4ae62c3884
6 changed files with 131 additions and 14 deletions

View File

@@ -8972,8 +8972,7 @@ namespace ts {
}
function getConstraintDeclaration(type: TypeParameter) {
const decl = type.symbol && getDeclarationOfKind<TypeParameterDeclaration>(type.symbol, SyntaxKind.TypeParameter);
return decl && getEffectiveConstraintOfTypeParameter(decl);
return mapDefined(filter(type.symbol && type.symbol.declarations, isTypeParameterDeclaration), getEffectiveConstraintOfTypeParameter)[0];
}
function getInferredTypeParameterConstraint(typeParameter: TypeParameter) {
@@ -29233,11 +29232,10 @@ namespace ts {
const constraint = getEffectiveConstraintOfTypeParameter(source);
const sourceConstraint = constraint && getTypeFromTypeNode(constraint);
const targetConstraint = getConstraintOfTypeParameter(target);
if (sourceConstraint) {
// relax check if later interface augmentation has no constraint
if (!targetConstraint || !isTypeIdenticalTo(sourceConstraint, targetConstraint)) {
return false;
}
// relax check if later interface augmentation has no constraint, it's more broad and is OK to merge with
// a more constrained interface (this could be generalized to a full heirarchy check, but that's maybe overkill)
if (sourceConstraint && targetConstraint && !isTypeIdenticalTo(sourceConstraint, targetConstraint)) {
return false;
}
// If the type parameter node has a default and it is not identical to the default