Let's say you extends from a base class, you intent to override a method in base class
class BaseCmp {
showCmp() {}
hideCmp() {}
helperMethod() {}
}
class MyCmp extends BaseCmp {
// we intent to override showCmp() method
// but we give a wrong method name
show() {}
}
Then showCmp
would never get called because of wrong name in extended class.
To avoid this issue, we can use `override
` keyword
class BaseCmp {
showCmp() {}
hideCmp() {}
helperMethod() {}
}
class MyCmp extends BaseCmp {
// we intent to override showCmp() method
// but we give a wrong method name
override showCmp() {}
}
Typescript will show error if method name cannot be found in BasedCmp
Let's imaging another issue that, from extends class, we don't intent to override helperMethod
, but we accidently did
class BaseCmp {
showCmp() {}
hideCmp() {}
helperMethod() {}
}
class MyCmp extends BaseCmp {
override showCmp() {}
// we don't really want override helperMethod()
helperMethod() {}
}
To avoid this problem, we can use `noImplicitOverride: true
` Once turn it on, Typescript will throw error, if you didn't add `override
` to show you intentation.