typescriptjsdoc

How to double cast a value in JSDoc typescript?


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.


Solution

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