Categories
TypeScript Answers

How to disable a TypeScript rule for a specific line?

Spread the love

Sometimes, we want to disable a TypeScript rule for a specific line.

In this article, we’ll look at how to disable a TypeScript rule for a specific line.

How to disable a TypeScript rule for a specific line?

To disable a TypeScript rule for a specific line, we can add a @ts-ignore comment.

For instance, we write

if (false) {
  // @ts-ignore: Unreachable code error
  console.log("hello");
}

to add the

// @ts-ignore: Unreachable code error

comment so the TypeScript compiler will ignore the unreachable compiler error.

Conclusion

To disable a TypeScript rule for a specific line, we can add a @ts-ignore comment.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *