typescript 如何对块使用`@ts-ignore`
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51145180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use `@ts-ignore` for a block
提问by garrettmaring
The // @ts-ignore
comment enables the Typescript compiler to ignore the line below it.
该// @ts-ignore
评论使打字稿编译器忽略它下面的线。
How can one ignore a whole block of code with Typescript?
如何使用 Typescript 忽略整个代码块?
采纳答案by Simon Warta
You can't. This is an open issue in TypeScript: https://github.com/Microsoft/TypeScript/issues/19573
你不能。这是 TypeScript 中的一个悬而未决的问题:https: //github.com/Microsoft/TypeScript/issues/19573
回答by Venryx
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/
作为一种解决方法,您可以使用// @ts-nocheck
文件顶部的注释来禁用该文件的类型检查:https: //devblogs.microsoft.com/typescript/annoucing-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.)
因此,要禁用对块(函数、类等)的检查,您可以将其移动到其自己的文件中,然后使用上面的注释/标志。(这当然不如基于块的禁用灵活,但它是目前可用的最佳选择。)