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

前端 未结 3 420
醉话见心
醉话见心 2021-01-31 01:05

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?

3条回答
  •  难免孤独
    2021-01-31 01:24

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

提交回复
热议问题