The analyzer has detected that a method does not override another method from the ancestor class or implement a method from an interface, although their signatures are very similar.
The example:
class ClassA {
public receiveArguments(arg1: string, arg2: number): void {
// ....
}
// ....
}
class ClassB extends ClassA {
recieveArguments(arg1: string, arg2: number): void { // <=
// ....
}
// ....
}
In the example, a typo is in the name of the receiveArguments method in the ClassB class. As a result, the method does not override the base class method as intended.
The fixed code:
class ClassB extends ClassA {
receiveArguments(arg1: string, arg2: number): void {
....
}
}
To avoid such errors related to method override in TypeScript, use the override keyword:
class ClassB extends ClassA {
override receiveArguments(arg1: string, arg2: number): void {
// ....
}
}
If the override keyword is specified, but the method does not override an existing method, the compiler reports an error and the program will not compile.
To make the override keyword mandatory for all overridden methods, the compiler's noImplicitOverride settings can be enabled in tsconfig.json.
{
"compilerOptions": {
"noImplicitOverride": true
}
}
To avoid such errors in JavaScript, use the @override JSDoc annotation to mark overriding methods. It allows development tools to generate special warnings on the non-existent method that is attempted to override.
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: