mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-25 16:07:52 -05:00
feat(44190): check misspelled base members in override checks (#44213)
This commit is contained in:
@@ -37308,7 +37308,10 @@ namespace ts {
|
||||
|
||||
const baseClassName = typeToString(baseWithThis);
|
||||
if (prop && !baseProp && hasOverride) {
|
||||
error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0, baseClassName);
|
||||
const suggestion = getSpellingSuggestionForName(symbolName(declaredProp), arrayFrom(getMembersOfSymbol(baseType.symbol).values()), SymbolFlags.ClassMember);
|
||||
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);
|
||||
}
|
||||
else if (prop && baseProp?.valueDeclaration && compilerOptions.noImplicitOverride && !nodeInAmbientContext) {
|
||||
const baseHasAbstract = hasAbstractModifier(baseProp.valueDeclaration);
|
||||
|
||||
@@ -3733,6 +3733,10 @@
|
||||
"category": "Error",
|
||||
"code": 4116
|
||||
},
|
||||
"This member cannot have an 'override' modifier because it is not declared in the base class '{0}'. Did you mean '{1}'?": {
|
||||
"category": "Error",
|
||||
"code": 4117
|
||||
},
|
||||
|
||||
"The current host does not support the '{0}' option.": {
|
||||
"category": "Error",
|
||||
|
||||
14
tests/baselines/reference/override15.errors.txt
Normal file
14
tests/baselines/reference/override15.errors.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
tests/cases/conformance/override/override15.ts(6,14): 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/override15.ts (1 errors) ====
|
||||
class A {
|
||||
doSomething() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
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'?
|
||||
}
|
||||
|
||||
40
tests/baselines/reference/override15.js
Normal file
40
tests/baselines/reference/override15.js
Normal file
@@ -0,0 +1,40 @@
|
||||
//// [override15.ts]
|
||||
class A {
|
||||
doSomething() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
override doSomethang() {}
|
||||
}
|
||||
|
||||
|
||||
//// [override15.js]
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
A.prototype.doSomething = function () { };
|
||||
return A;
|
||||
}());
|
||||
var B = /** @class */ (function (_super) {
|
||||
__extends(B, _super);
|
||||
function B() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
B.prototype.doSomethang = function () { };
|
||||
return B;
|
||||
}(A));
|
||||
16
tests/baselines/reference/override15.symbols
Normal file
16
tests/baselines/reference/override15.symbols
Normal file
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/conformance/override/override15.ts ===
|
||||
class A {
|
||||
>A : Symbol(A, Decl(override15.ts, 0, 0))
|
||||
|
||||
doSomething() {}
|
||||
>doSomething : Symbol(A.doSomething, Decl(override15.ts, 0, 9))
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
>B : Symbol(B, Decl(override15.ts, 2, 1))
|
||||
>A : Symbol(A, Decl(override15.ts, 0, 0))
|
||||
|
||||
override doSomethang() {}
|
||||
>doSomethang : Symbol(B.doSomethang, Decl(override15.ts, 4, 19))
|
||||
}
|
||||
|
||||
16
tests/baselines/reference/override15.types
Normal file
16
tests/baselines/reference/override15.types
Normal file
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/conformance/override/override15.ts ===
|
||||
class A {
|
||||
>A : A
|
||||
|
||||
doSomething() {}
|
||||
>doSomething : () => void
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
>B : B
|
||||
>A : A
|
||||
|
||||
override doSomethang() {}
|
||||
>doSomethang : () => void
|
||||
}
|
||||
|
||||
9
tests/cases/conformance/override/override15.ts
Normal file
9
tests/cases/conformance/override/override15.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
// @noImplicitOverride: true
|
||||
|
||||
class A {
|
||||
doSomething() {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
override doSomethang() {}
|
||||
}
|
||||
Reference in New Issue
Block a user