mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-06 15:24:36 -05:00
Emit error on class fields named "constructor"
This commit is contained in:
@@ -31789,6 +31789,9 @@ namespace ts {
|
||||
|
||||
function checkGrammarProperty(node: PropertyDeclaration | PropertySignature) {
|
||||
if (isClassLike(node.parent)) {
|
||||
if (isStringLiteral(node.name) && node.name.text === "constructor") {
|
||||
return grammarErrorOnNode(node.name, Diagnostics.Classes_may_not_have_a_field_named_constructor);
|
||||
}
|
||||
if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4958,5 +4958,9 @@
|
||||
"Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '[\"constructor\"]()' to write a method.": {
|
||||
"category": "Error",
|
||||
"code": 18005
|
||||
},
|
||||
"Classes may not have a field named 'constructor'.": {
|
||||
"category": "Error",
|
||||
"code": 18006
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user