mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Variance annotations on class expressions + deferred valiation (#48645)
* Variance annotations on class expressions + deferred validation * Add regression tests
This commit is contained in:
@@ -34838,11 +34838,17 @@ namespace ts {
|
||||
if (constraintType && defaultType) {
|
||||
checkTypeAssignableTo(defaultType, getTypeWithThisArgument(instantiateType(constraintType, makeUnaryTypeMapper(typeParameter, defaultType)), defaultType), node.default, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
|
||||
}
|
||||
if (node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.ClassDeclaration || node.parent.kind === SyntaxKind.TypeAliasDeclaration) {
|
||||
checkNodeDeferred(node);
|
||||
addLazyDiagnostic(() => checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0));
|
||||
}
|
||||
|
||||
function checkTypeParameterDeferred(node: TypeParameterDeclaration) {
|
||||
if (isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent)) {
|
||||
const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node));
|
||||
const modifiers = getVarianceModifiers(typeParameter);
|
||||
if (modifiers) {
|
||||
const symbol = getSymbolOfNode(node.parent);
|
||||
if (node.parent.kind === SyntaxKind.TypeAliasDeclaration && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (ObjectFlags.Anonymous | ObjectFlags.Mapped))) {
|
||||
if (isTypeAliasDeclaration(node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (ObjectFlags.Anonymous | ObjectFlags.Mapped))) {
|
||||
error(node, Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types);
|
||||
}
|
||||
else if (modifiers === ModifierFlags.In || modifiers === ModifierFlags.Out) {
|
||||
@@ -34855,7 +34861,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
addLazyDiagnostic(() => checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0));
|
||||
}
|
||||
|
||||
function checkParameter(node: ParameterDeclaration) {
|
||||
@@ -41354,6 +41359,9 @@ namespace ts {
|
||||
case SyntaxKind.ClassExpression:
|
||||
checkClassExpressionDeferred(node as ClassExpression);
|
||||
break;
|
||||
case SyntaxKind.TypeParameter:
|
||||
checkTypeParameterDeferred(node as TypeParameterDeclaration);
|
||||
break;
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
checkJsxSelfClosingElementDeferred(node as JsxSelfClosingElement);
|
||||
break;
|
||||
@@ -43551,8 +43559,7 @@ namespace ts {
|
||||
case SyntaxKind.OutKeyword:
|
||||
const inOutFlag = modifier.kind === SyntaxKind.InKeyword ? ModifierFlags.In : ModifierFlags.Out;
|
||||
const inOutText = modifier.kind === SyntaxKind.InKeyword ? "in" : "out";
|
||||
if (node.kind !== SyntaxKind.TypeParameter || (node.parent.kind !== SyntaxKind.InterfaceDeclaration &&
|
||||
node.parent.kind !== SyntaxKind.ClassDeclaration && node.parent.kind !== SyntaxKind.TypeAliasDeclaration)) {
|
||||
if (node.kind !== SyntaxKind.TypeParameter || !(isInterfaceDeclaration(node.parent) || isClassLike(node.parent) || isTypeAliasDeclaration(node.parent))) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias, inOutText);
|
||||
}
|
||||
if (flags & inOutFlag) {
|
||||
|
||||
Reference in New Issue
Block a user