Question

[Solved] How to use `@ts-ignore` for a block

The // @ts-ignore comment enables the Typescript compiler to ignore the line below it.

How can one ignore a whole block of code with Typescript?

Solution #1:

You can’t. This is an open issue in TypeScript: https://github.com/Microsoft/TypeScript/issues/19573

Respondent: garrettmaring

Solution #2:

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.)

Respondent: Simon Warta

Solution #3:

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

Respondent: Venryx

Solution #4:

If you don’t need typesafe, just bring block to a new separated file and change the extension to .js,.jsx

Respondent: Felipe Pereira

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy