Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use `@ts-ignore` for a block?

People also ask

How do I ts ignore a block of code?

You can ignore type checking errors for a single line by using the // @ts-ignore comment. Copied! The // @ts-ignore comment ignores any type checking errors that occur on the next line. If you use a linter, you might get an error when you use a comment to disable type checking for a line, or for the entire file.

What is TS ignore used for?

A // @ts-ignore comment suppresses all errors that originate on the following line. It is recommended practice to have the remainder of the comment following @ts-ignore explain which error is being suppressed.

How do I ignore TypeScript in one line?

Use the // @ts-ignore comment to disable type checking for a line in TypeScript. The comment disables type checking for the next line. If you use a linter, you might need to disable it for the line on which you use the // @ts-ignore comment.

How do I disable .TS file?

Use the // @ts-nocheck comment to disable type checking for an entire file in TypeScript. The // @ts-nocheck comment instructs TypeScript to skip the file when type checking. If you use a linter, you might need to disable it on the line of the comment. Copied!


You can't. This is an open issue in TypeScript.


You can't.

As a workaround you can use a // @ts-nocheck comment at the top of a file to disable type-checking for that file: https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-beta/

So to disable checking for a block (function, class, etc.), you can move it into its own file, then use the comment/flag above. (This isn't as flexible as block-based disabling of course, but it's the best option available at the moment.)


There is

// @ts-nocheck

It can be added at the beginning of the file and all errors in it will be ignored, isn't the block specific answer you are looking for but in some scenarios it is equivalent.

https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/#ts-nocheck-in-typescript-files