DEV Community

Cover image for #noImplicitOverride in tsconfig.json
Brian Opedal
Brian Opedal

Posted on

#noImplicitOverride in tsconfig.json

Set noImplicitOverride: true

It lets Typescript do more of what typescript is meant to do.
And its usually a quick and easy increase of type-safety in your codebase.

#noImplicitOverride

Here are 3 reasons why you should set tsconfig.json #noImplicitOverride

  1. Prevents Overrides that don't actually override:

It prevents your developers from mistakenly thinking they are overriding something when they are not, preventing errors like spelling mistakes or attempting to override a removed/updated method/variable on the base class.

  1. Ensures Up-to-Date Sub-classes:

Lets Typescript give an error if a subclass becomes outdated due to changes in the base class, such as the removal or modification of a method.

  1. Requires Explicit Method Signature:

The override keyword shows clearly what the intention
of the method is. If it's not there you would have to go to the base class (and potentially to its base and so forth) to see if the method is overridden or not.

How to do it?

a. In your tsconfig.json just add:

{
    "compilerOptions": {
        ...
        "noImplicitOverride": true
    }
}

Enter fullscreen mode Exit fullscreen mode

b. run a typecheck and fix all classes by adding override to the methods and class variables.

Top comments (0)