fix(53242): Wrong error message when defined abstract property in non-abstract class (#53251)

This commit is contained in:
Oleksandr T 2023-03-14 20:10:40 +02:00 committed by GitHub
parent e08a2db86d
commit 2378c0b65e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -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");

View File

@ -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

View File

@ -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.