@@ -34838,11 +34838,17 @@ namespace ts {
3483834838 if (constraintType && defaultType) {
3483934839 checkTypeAssignableTo(defaultType, getTypeWithThisArgument(instantiateType(constraintType, makeUnaryTypeMapper(typeParameter, defaultType)), defaultType), node.default, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
3484034840 }
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));
3484234848 const modifiers = getVarianceModifiers(typeParameter);
3484334849 if (modifiers) {
3484434850 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))) {
3484634852 error(node, Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types);
3484734853 }
3484834854 else if (modifiers === ModifierFlags.In || modifiers === ModifierFlags.Out) {
@@ -34855,7 +34861,6 @@ namespace ts {
3485534861 }
3485634862 }
3485734863 }
34858- addLazyDiagnostic(() => checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0));
3485934864 }
3486034865
3486134866 function checkParameter(node: ParameterDeclaration) {
@@ -41354,6 +41359,9 @@ namespace ts {
4135441359 case SyntaxKind.ClassExpression:
4135541360 checkClassExpressionDeferred(node as ClassExpression);
4135641361 break;
41362+ case SyntaxKind.TypeParameter:
41363+ checkTypeParameterDeferred(node as TypeParameterDeclaration);
41364+ break;
4135741365 case SyntaxKind.JsxSelfClosingElement:
4135841366 checkJsxSelfClosingElementDeferred(node as JsxSelfClosingElement);
4135941367 break;
@@ -43551,8 +43559,7 @@ namespace ts {
4355143559 case SyntaxKind.OutKeyword:
4355243560 const inOutFlag = modifier.kind === SyntaxKind.InKeyword ? ModifierFlags.In : ModifierFlags.Out;
4355343561 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))) {
4355643563 return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias, inOutText);
4355743564 }
4355843565 if (flags & inOutFlag) {
0 commit comments