简体   繁体   English

保留@typescript-eslint/require-await,但豁免个别实例?

[英]Leaving @typescript-eslint/require-await on, but exempting individual instances?

I have a project where there have recently been a slew of recent bugs where async functions are not being awaited, resulting in some test infrastructure timeouts.我有一个项目,其中最近出现了一系列错误,其中没有等待异步函数,导致一些测试基础设施超时。 We use typescript-esling, and I'd love to be able to enable the flag @typescript-eslint/require-await as an error, but there are times that I want exceptions: intentionally unawaited async calls.我们使用 typescript-esling,我希望能够启用标志@typescript-eslint/require-await作为错误,但有时我想要例外:故意未等待的异步调用。

Is there JS/TS syntax I can use to indicate to the linter that a given line has been intentionally not awaited?是否有 JS/TS 语法可以用来向 linter 指示故意不等待给定行? I'm hoping there's something similar to how discards will avoid the "variable not used" rule.我希望有一些类似于丢弃如何避免“变量未使用”规则的东西。 Thanks!谢谢!

Put a void in front of the unawaited promise.在未等待的 promise 前面放一个void (potentially needs another rule to allow this, depending on your presets) (可能需要另一个规则来允许这样做,具体取决于您的预设)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM