如何在 JSDoc 打字稿中双重转换值?

发布于 2025-01-13 23:46:34 字数 292 浏览 2 评论 0原文

出现 TS 2352 错误:

类型“X”到类型“Y”的转换可能是一个错误,因为两种类型都没有与另一种类型充分重叠。如果这是故意的,请首先将表达式转换为“未知”。 ... ts(2352)

如何首先将表达式转换为“未知”?我已经在 J​​SDoc 打字稿中进行了一次转换:

/** @type {Y} */ (variableOfTypeX)

我在任何地方都找不到这方面的文档。

Getting the TS 2352 error:

Conversion of type 'X' to type 'Y' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. ... ts(2352)

How do I convert the expression to 'unknown' first? I am already doing a single cast in JSDoc typescript:

/** @type {Y} */ (variableOfTypeX)

I can't find the documentation for this anywhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命比纸薄 2025-01-20 23:46:34

通过尝试和失败,我发现这是如何在 JSDoc 打字稿中双重转换值(首先转换为未知,然后转换为 Y):

/** @type {Y} */ (/** @type {unknown} */ (variableOfTypeX))

By trying and failing, I found this is how to double cast a value in JSDoc typescript (first to unknown and then to Y):

/** @type {Y} */ (/** @type {unknown} */ (variableOfTypeX))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文