diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cc23103403e..9c810809f0f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4553,6 +4553,9 @@ namespace ts { result &= stringIndexTypesRelatedTo(source, target, reportErrors); if (result) { result &= numberIndexTypesRelatedTo(source, target, reportErrors); + // if(relation == subtypeRelation && result) { + // result &= abstractnessRelatedTo(source, target, reportErrors); + // } } } } @@ -4574,6 +4577,17 @@ namespace ts { return result; } + function abstractnessRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { + if ( source.symbol && target.symbol && getDeclarationFlagsFromSymbol(source.symbol) & NodeFlags.Abstract && + !(getDeclarationFlagsFromSymbol(target.symbol) & NodeFlags.Abstract)) { + if (reportErrors) { + reportError(Diagnostics.Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type); + } + return Ternary.False; + } + return Ternary.True; + } + function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 853ee81359c..89c6e8bf109 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -399,6 +399,7 @@ namespace ts { Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." }, Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." }, All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." }, + Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 3605bae6900..fa50f5cdcc5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1583,6 +1583,10 @@ "category": "Error", "code": 2516 }, + "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type": { + "category": "Error", + "code":2517 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000