@@ -5948,7 +5948,8 @@ namespace ts {
5948
5948
5949
5949
/** A type parameter is thisless if its contraint is thisless, or if it has no constraint. */
5950
5950
function isThislessTypeParameter(node: TypeParameterDeclaration) {
5951
- return !node.constraint || isThislessType(node.constraint);
5951
+ const constraint = getEffectiveConstraintOfTypeParameter(node);
5952
+ return !constraint || isThislessType(constraint);
5952
5953
}
5953
5954
5954
5955
/**
@@ -6735,7 +6736,7 @@ namespace ts {
6735
6736
}
6736
6737
6737
6738
function getConstraintDeclarationForMappedType(type: MappedType) {
6738
- return type.declaration.typeParameter.constraint ;
6739
+ return getEffectiveConstraintOfTypeParameter( type.declaration.typeParameter) ;
6739
6740
}
6740
6741
6741
6742
function isMappedTypeWithKeyofConstraintDeclaration(type: MappedType) {
@@ -7872,7 +7873,7 @@ namespace ts {
7872
7873
7873
7874
function getConstraintDeclaration(type: TypeParameter) {
7874
7875
const decl = type.symbol && getDeclarationOfKind<TypeParameterDeclaration>(type.symbol, SyntaxKind.TypeParameter);
7875
- return decl && decl.constraint ;
7876
+ return decl && getEffectiveConstraintOfTypeParameter( decl) ;
7876
7877
}
7877
7878
7878
7879
function getInferredTypeParameterConstraint(typeParameter: TypeParameter) {
@@ -22016,7 +22017,7 @@ namespace ts {
22016
22017
checkSourceElement(node.default);
22017
22018
const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node));
22018
22019
if (!hasNonCircularBaseConstraint(typeParameter)) {
22019
- error(node.constraint , Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter));
22020
+ error(getEffectiveConstraintOfTypeParameter( node) , Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter));
22020
22021
}
22021
22022
if (!hasNonCircularTypeParameterDefault(typeParameter)) {
22022
22023
error(node.default, Diagnostics.Type_parameter_0_has_a_circular_default, typeToString(typeParameter));
@@ -22749,7 +22750,7 @@ namespace ts {
22749
22750
22750
22751
const type = <MappedType>getTypeFromMappedTypeNode(node);
22751
22752
const constraintType = getConstraintTypeFromMappedType(type);
22752
- checkTypeAssignableTo(constraintType, keyofConstraintType, node.typeParameter.constraint );
22753
+ checkTypeAssignableTo(constraintType, keyofConstraintType, getEffectiveConstraintOfTypeParameter( node.typeParameter) );
22753
22754
}
22754
22755
22755
22756
function checkThisType(node: ThisTypeNode) {
@@ -23640,6 +23641,13 @@ namespace ts {
23640
23641
checkSourceElement(node.typeExpression);
23641
23642
}
23642
23643
23644
+ function checkJSDocTemplateTag(node: JSDocTemplateTag): void {
23645
+ checkSourceElement(node.constraint);
23646
+ for (const tp of node.typeParameters) {
23647
+ checkSourceElement(tp);
23648
+ }
23649
+ }
23650
+
23643
23651
function checkJSDocTypeTag(node: JSDocTypeTag) {
23644
23652
checkSourceElement(node.typeExpression);
23645
23653
}
@@ -25427,7 +25435,8 @@ namespace ts {
25427
25435
25428
25436
// If the type parameter node does not have an identical constraint as the resolved
25429
25437
// type parameter at this position, we report an error.
25430
- const sourceConstraint = source.constraint && getTypeFromTypeNode(source.constraint);
25438
+ const constraint = getEffectiveConstraintOfTypeParameter(source);
25439
+ const sourceConstraint = constraint && getTypeFromTypeNode(constraint);
25431
25440
const targetConstraint = getConstraintOfTypeParameter(target);
25432
25441
if (sourceConstraint) {
25433
25442
// relax check if later interface augmentation has no constraint
@@ -26647,6 +26656,8 @@ namespace ts {
26647
26656
case SyntaxKind.JSDocTypedefTag:
26648
26657
case SyntaxKind.JSDocCallbackTag:
26649
26658
return checkJSDocTypeAliasTag(node as JSDocTypedefTag);
26659
+ case SyntaxKind.JSDocTemplateTag:
26660
+ return checkJSDocTemplateTag(node as JSDocTemplateTag);
26650
26661
case SyntaxKind.JSDocTypeTag:
26651
26662
return checkJSDocTypeTag(node as JSDocTypeTag);
26652
26663
case SyntaxKind.JSDocParameterTag:
@@ -29763,6 +29774,13 @@ namespace ts {
29763
29774
}
29764
29775
return false;
29765
29776
}
29777
+
29778
+ function getEffectiveConstraintOfTypeParameter(node: TypeParameterDeclaration): TypeNode | undefined {
29779
+ return node.constraint ? node.constraint
29780
+ : isJSDocTemplateTag(node.parent) && node === node.parent.typeParameters[0]
29781
+ ? node.parent.constraint
29782
+ : undefined;
29783
+ }
29766
29784
}
29767
29785
29768
29786
/** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */
0 commit comments