diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2515d81a58f..6faedec065b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47002,7 +47002,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration); } if (!(node.parent.kind === SyntaxKind.ClassDeclaration && hasSyntacticModifier(node.parent, ModifierFlags.Abstract))) { - return grammarErrorOnNode(modifier, Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); + const message = node.kind === SyntaxKind.PropertyDeclaration + ? Diagnostics.Abstract_properties_can_only_appear_within_an_abstract_class + : Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class; + return grammarErrorOnNode(modifier, message); } if (flags & ModifierFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract"); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f3c9c5d11cd..8a3f57b7643 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -811,6 +811,10 @@ "category": "Error", "code": 1252 }, + "Abstract properties can only appear within an abstract class.": { + "category": "Error", + "code": 1253 + }, "A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.": { "category": "Error", "code": 1254 diff --git a/tests/baselines/reference/abstractPropertyNegative.errors.txt b/tests/baselines/reference/abstractPropertyNegative.errors.txt index d7b2fa592f8..70e4c825dd0 100644 --- a/tests/baselines/reference/abstractPropertyNegative.errors.txt +++ b/tests/baselines/reference/abstractPropertyNegative.errors.txt @@ -3,7 +3,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstra tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'. tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'readonlyProp' from class 'B'. -tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class. +tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1253: Abstract properties can only appear within an abstract class. tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected. tests/cases/compiler/abstractPropertyNegative.ts(19,3): error TS2540: Cannot assign to 'ro' because it is a read-only property. tests/cases/compiler/abstractPropertyNegative.ts(25,5): error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'WrongTypeProperty'. @@ -45,7 +45,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors readonly ro = "readonly please"; abstract notAllowed: string; ~~~~~~~~ -!!! error TS1244: Abstract methods can only appear within an abstract class. +!!! error TS1253: Abstract properties can only appear within an abstract class. get concreteWithNoBody(): string; ~ !!! error TS1005: '{' expected.