@@ -34838,11 +34838,17 @@ namespace ts {
34838
34838
if (constraintType && defaultType) {
34839
34839
checkTypeAssignableTo(defaultType, getTypeWithThisArgument(instantiateType(constraintType, makeUnaryTypeMapper(typeParameter, defaultType)), defaultType), node.default, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
34840
34840
}
34841
- if (node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.ClassDeclaration || node.parent.kind === SyntaxKind.TypeAliasDeclaration) {
34841
+ checkNodeDeferred(node);
34842
+ addLazyDiagnostic(() => checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0));
34843
+ }
34844
+
34845
+ function checkTypeParameterDeferred(node: TypeParameterDeclaration) {
34846
+ if (isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent)) {
34847
+ const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node));
34842
34848
const modifiers = getVarianceModifiers(typeParameter);
34843
34849
if (modifiers) {
34844
34850
const symbol = getSymbolOfNode(node.parent);
34845
- if (node.parent.kind === SyntaxKind.TypeAliasDeclaration && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (ObjectFlags.Anonymous | ObjectFlags.Mapped))) {
34851
+ if (isTypeAliasDeclaration( node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (ObjectFlags.Anonymous | ObjectFlags.Mapped))) {
34846
34852
error(node, Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types);
34847
34853
}
34848
34854
else if (modifiers === ModifierFlags.In || modifiers === ModifierFlags.Out) {
@@ -34855,7 +34861,6 @@ namespace ts {
34855
34861
}
34856
34862
}
34857
34863
}
34858
- addLazyDiagnostic(() => checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0));
34859
34864
}
34860
34865
34861
34866
function checkParameter(node: ParameterDeclaration) {
@@ -41354,6 +41359,9 @@ namespace ts {
41354
41359
case SyntaxKind.ClassExpression:
41355
41360
checkClassExpressionDeferred(node as ClassExpression);
41356
41361
break;
41362
+ case SyntaxKind.TypeParameter:
41363
+ checkTypeParameterDeferred(node as TypeParameterDeclaration);
41364
+ break;
41357
41365
case SyntaxKind.JsxSelfClosingElement:
41358
41366
checkJsxSelfClosingElementDeferred(node as JsxSelfClosingElement);
41359
41367
break;
@@ -43551,8 +43559,7 @@ namespace ts {
43551
43559
case SyntaxKind.OutKeyword:
43552
43560
const inOutFlag = modifier.kind === SyntaxKind.InKeyword ? ModifierFlags.In : ModifierFlags.Out;
43553
43561
const inOutText = modifier.kind === SyntaxKind.InKeyword ? "in" : "out";
43554
- if (node.kind !== SyntaxKind.TypeParameter || (node.parent.kind !== SyntaxKind.InterfaceDeclaration &&
43555
- node.parent.kind !== SyntaxKind.ClassDeclaration && node.parent.kind !== SyntaxKind.TypeAliasDeclaration)) {
43562
+ if (node.kind !== SyntaxKind.TypeParameter || !(isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent))) {
43556
43563
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias, inOutText);
43557
43564
}
43558
43565
if (flags & inOutFlag) {
0 commit comments