TSConfig
noImplicitOverride
When working with classes which use inheritance, it’s possible for a sub-class to get “out of sync” with the functions it overloads when they are renamed in the base class.
For example, imagine you are modeling a music album syncing system:
tsTryclassAlbum {download () {// Default behavior}}classSharedAlbum extendsAlbum {download () {// Override to get info from many sources}}
Then when you add support for machine-learning generated playlists, you refactor the Album class to have a ‘setup’ function instead:
tsTryclassAlbum {setup () {// Default behavior}}classMLAlbum extendsAlbum {setup () {// Override to get info from algorithm}}classSharedAlbum extendsAlbum {download () {// Override to get info from many sources}}
In this case, TypeScript has provided no warning that download on SharedAlbum expected to override a function in the base class.
Using noImplicitOverride you can ensure that the sub-classes never go out of sync, by ensuring that functions which override include the keyword override.
The following example has noImplicitOverride enabled, and you can see the error received when override is missing:
tsTryclassAlbum {setup () {}}classMLAlbum extendsAlbum {overridesetup () {}}classSharedAlbum extendsAlbum {This member must have an 'override' modifier because it overrides a member in the base class 'Album'.4114This member must have an 'override' modifier because it overrides a member in the base class 'Album'.() {} setup }