Cherry-pick PR #33426 into release-3.6

Component commits:
4ae62c3884 getConstraintDeclaration gets the first declaration with a constraint, rather than just the first declaration

b1ad54b382 Add type annotation

2232f5ebaa Update comment
This commit is contained in:
Wesley Wigham
2019-09-19 17:51:15 +00:00
committed by typescript-bot
parent 46ccaa29d6
commit 391a73b598
10 changed files with 137 additions and 20 deletions

View File

@@ -8940,9 +8940,8 @@ namespace ts {
return undefined;
}
function getConstraintDeclaration(type: TypeParameter) {
const decl = type.symbol && getDeclarationOfKind<TypeParameterDeclaration>(type.symbol, SyntaxKind.TypeParameter);
return decl && getEffectiveConstraintOfTypeParameter(decl);
function getConstraintDeclaration(type: TypeParameter): TypeNode | undefined {
return mapDefined(filter(type.symbol && type.symbol.declarations, isTypeParameterDeclaration), getEffectiveConstraintOfTypeParameter)[0];
}
function getInferredTypeParameterConstraint(typeParameter: TypeParameter) {
@@ -29185,11 +29184,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