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

问题描述 投票:0回答:1

收到 TS 2352 错误:

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)

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

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

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

typescript jsdoc
1个回答
9
投票

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

/** @type {Y} */ (/** @type {unknown} */ (variableOfTypeX))
© www.soinside.com 2019 - 2024. All rights reserved.