fix: add corresponding message for override error in js files (#45656)
* fix: add override errors for js class members * fix: test failures of js override error message * update diagnostic messages * fix: test errors * fix: lint errors
This commit is contained in:
parent
b2f9432c40
commit
add85e1828
|
@ -38042,6 +38042,7 @@ namespace ts {
|
|||
function checkClassMember(member: ClassElement | ParameterPropertyDeclaration, memberIsParameterProperty?: boolean) {
|
||||
const hasOverride = hasOverrideModifier(member);
|
||||
const hasStatic = isStatic(member);
|
||||
const isJs = isInJSFile(member);
|
||||
if (baseWithThis && (hasOverride || compilerOptions.noImplicitOverride)) {
|
||||
const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member);
|
||||
if (!declaredProp) {
|
||||
|
@ -38057,8 +38058,19 @@ namespace ts {
|
|||
if (prop && !baseProp && hasOverride) {
|
||||
const suggestion = getSuggestedSymbolForNonexistentClassMember(symbolName(declaredProp), baseType);
|
||||
suggestion ?
|
||||
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1, baseClassName, symbolToString(suggestion)) :
|
||||
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0, baseClassName);
|
||||
error(
|
||||
member,
|
||||
isJs ?
|
||||
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1 :
|
||||
Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1,
|
||||
baseClassName,
|
||||
symbolToString(suggestion)) :
|
||||
error(
|
||||
member,
|
||||
isJs ?
|
||||
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0 :
|
||||
Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0,
|
||||
baseClassName);
|
||||
}
|
||||
else if (prop && baseProp?.declarations && compilerOptions.noImplicitOverride && !nodeInAmbientContext) {
|
||||
const baseHasAbstract = some(baseProp.declarations, hasAbstractModifier);
|
||||
|
@ -38068,8 +38080,12 @@ namespace ts {
|
|||
|
||||
if (!baseHasAbstract) {
|
||||
const diag = memberIsParameterProperty ?
|
||||
Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0 :
|
||||
Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0;
|
||||
isJs ?
|
||||
Diagnostics.This_parameter_property_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0 :
|
||||
Diagnostics.This_parameter_property_must_have_an_override_modifier_because_it_overrides_a_member_in_base_class_0 :
|
||||
isJs ?
|
||||
Diagnostics.This_member_must_have_a_JSDoc_comment_with_an_override_tag_because_it_overrides_a_member_in_the_base_class_0 :
|
||||
Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0;
|
||||
error(member, diag, baseClassName);
|
||||
}
|
||||
else if (hasAbstractModifier(member) && baseHasAbstract) {
|
||||
|
@ -38079,7 +38095,12 @@ namespace ts {
|
|||
}
|
||||
else if (hasOverride) {
|
||||
const className = typeToString(type);
|
||||
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class, className);
|
||||
error(
|
||||
member,
|
||||
isJs ?
|
||||
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_its_containing_class_0_does_not_extend_another_class :
|
||||
Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class,
|
||||
className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3709,7 +3709,26 @@
|
|||
"category": "Error",
|
||||
"code": 4118
|
||||
},
|
||||
|
||||
"This member must have a JSDoc comment with an '@override' tag because it overrides a member in the base class '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 4119
|
||||
},
|
||||
"This parameter property must have a JSDoc comment with an '@override' tag because it overrides a member in the base class '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 4120
|
||||
},
|
||||
"This member cannot have a JSDoc comment with an '@override' tag because its containing class '{0}' does not extend another class.": {
|
||||
"category": "Error",
|
||||
"code": 4121
|
||||
},
|
||||
"This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 4122
|
||||
},
|
||||
"This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class '{0}'. Did you mean '{1}'?": {
|
||||
"category": "Error",
|
||||
"code": 4123
|
||||
},
|
||||
"The current host does not support the '{0}' option.": {
|
||||
"category": "Error",
|
||||
"code": 5001
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace ts.codefix {
|
|||
Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0.code,
|
||||
Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2.code,
|
||||
Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1.code,
|
||||
Diagnostics.This_member_cannot_have_a_JSDoc_comment_with_an_override_tag_because_it_is_not_declared_in_the_base_class_0_Did_you_mean_1.code,
|
||||
// for JSX class components
|
||||
Diagnostics.No_overload_matches_this_call.code,
|
||||
// for JSX FC
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
tests/cases/conformance/jsdoc/0.js(27,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'A'.
|
||||
tests/cases/conformance/jsdoc/0.js(32,5): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'A'.
|
||||
tests/cases/conformance/jsdoc/0.js(40,5): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class.
|
||||
tests/cases/conformance/jsdoc/0.js(27,5): error TS4119: This member must have a JSDoc comment with an '@override' tag because it overrides a member in the base class 'A'.
|
||||
tests/cases/conformance/jsdoc/0.js(32,5): error TS4122: This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class 'A'.
|
||||
tests/cases/conformance/jsdoc/0.js(40,5): error TS4121: This member cannot have a JSDoc comment with an '@override' tag because its containing class 'C' does not extend another class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/0.js (3 errors) ====
|
||||
|
@ -32,14 +32,14 @@ tests/cases/conformance/jsdoc/0.js(40,5): error TS4112: This member cannot have
|
|||
|
||||
bar () {
|
||||
~~~
|
||||
!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'A'.
|
||||
!!! error TS4119: This member must have a JSDoc comment with an '@override' tag because it overrides a member in the base class 'A'.
|
||||
|
||||
}
|
||||
|
||||
/** @override */
|
||||
baz () {
|
||||
~~~
|
||||
!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'A'.
|
||||
!!! error TS4122: This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class 'A'.
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ tests/cases/conformance/jsdoc/0.js(40,5): error TS4112: This member cannot have
|
|||
/** @override */
|
||||
foo () {
|
||||
~~~
|
||||
!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class.
|
||||
!!! error TS4121: This member cannot have a JSDoc comment with an '@override' tag because its containing class 'C' does not extend another class.
|
||||
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
tests/cases/conformance/override/a.js(7,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'.
|
||||
tests/cases/conformance/override/a.js(11,5): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'.
|
||||
tests/cases/conformance/override/a.js(17,5): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class.
|
||||
tests/cases/conformance/override/a.js(19,5): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class.
|
||||
tests/cases/conformance/override/a.js(7,5): error TS4119: This member must have a JSDoc comment with an '@override' tag because it overrides a member in the base class 'B'.
|
||||
tests/cases/conformance/override/a.js(11,5): error TS4122: This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class 'B'.
|
||||
tests/cases/conformance/override/a.js(17,5): error TS4121: This member cannot have a JSDoc comment with an '@override' tag because its containing class 'C' does not extend another class.
|
||||
tests/cases/conformance/override/a.js(19,5): error TS4121: This member cannot have a JSDoc comment with an '@override' tag because its containing class 'C' does not extend another class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/override/a.js (4 errors) ====
|
||||
|
@ -13,13 +13,13 @@ tests/cases/conformance/override/a.js(19,5): error TS4112: This member cannot ha
|
|||
class D extends B {
|
||||
foo (v) {}
|
||||
~~~
|
||||
!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'.
|
||||
!!! error TS4119: This member must have a JSDoc comment with an '@override' tag because it overrides a member in the base class 'B'.
|
||||
/** @override */
|
||||
fooo (v) {}
|
||||
/** @override */
|
||||
bar(v) {}
|
||||
~~~
|
||||
!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'.
|
||||
!!! error TS4122: This member cannot have a JSDoc comment with an '@override' tag because it is not declared in the base class 'B'.
|
||||
}
|
||||
|
||||
class C {
|
||||
|
@ -27,9 +27,9 @@ tests/cases/conformance/override/a.js(19,5): error TS4112: This member cannot ha
|
|||
/** @override */
|
||||
fooo (v) {}
|
||||
~~~~
|
||||
!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class.
|
||||
!!! error TS4121: This member cannot have a JSDoc comment with an '@override' tag because its containing class 'C' does not extend another class.
|
||||
/** @override */
|
||||
bar(v) {}
|
||||
~~~
|
||||
!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class.
|
||||
!!! error TS4121: This member cannot have a JSDoc comment with an '@override' tag because its containing class 'C' does not extend another class.
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
tests/cases/conformance/override/a.js(7,5): error TS4117: This member cannot have an 'override' modifier because it is not declared in the base class 'A'. Did you mean 'doSomething'?
|
||||
tests/cases/conformance/override/a.js(7,5): error TS4123: This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class 'A'. Did you mean 'doSomething'?
|
||||
|
||||
|
||||
==== tests/cases/conformance/override/a.js (1 errors) ====
|
||||
|
@ -10,6 +10,6 @@ tests/cases/conformance/override/a.js(7,5): error TS4117: This member cannot hav
|
|||
/** @override */
|
||||
doSomethang() {}
|
||||
~~~~~~~~~~~
|
||||
!!! error TS4117: This member cannot have an 'override' modifier because it is not declared in the base class 'A'. Did you mean 'doSomething'?
|
||||
!!! error TS4123: This member cannot have a JSDoc comment with an 'override' tag because it is not declared in the base class 'A'. Did you mean 'doSomething'?
|
||||
}
|
||||
|
Loading…
Reference in a new issue