I've been trying to use jsdoc
with ts-check
for error check/autoplete/intellisense, the only issue i've been having are selections (which i cannot cast as i do not use typescript).
when i try to set the type of an element it will instead underline it and display the following error
Type 'HTMLElement | null' is not assignable to type 'HTMLInputElement'
// @ts-check
/**
* @type {HTMLInputElement}
*/
const { list } = document.getElementById(someInput)
if i remove ts-check
it will remove the error and offer intellisense
but it will not show errors anymore.
I have been looking for solutions to this issue but they are all for typescript .
I've been trying to use jsdoc
with ts-check
for error check/autoplete/intellisense, the only issue i've been having are selections (which i cannot cast as i do not use typescript).
when i try to set the type of an element it will instead underline it and display the following error
Type 'HTMLElement | null' is not assignable to type 'HTMLInputElement'
// @ts-check
/**
* @type {HTMLInputElement}
*/
const { list } = document.getElementById(someInput)
if i remove ts-check
it will remove the error and offer intellisense
but it will not show errors anymore.
I have been looking for solutions to this issue but they are all for typescript .
Share Improve this question asked Dec 22, 2022 at 16:26 Dumitru BirsanDumitru Birsan 8568 silver badges15 bronze badges 2-
document.getElementById(someInput)
returnsHTMLElement | null
, you may not always be able to de-structure it to getlist
. If you're using VSCode, it might be worth using ESLint in bination with typescript installed. If you want typescript checking, why not use typescript? – Harrison Commented Dec 22, 2022 at 16:33 - 2 @Harrison jsdoc + typescript solve most of the problems and remove pilation step which may significantly slowdown development. Also, I like the idea of types in ments because it doesn't allow you to use syntax different from JavaScript (like enums) and clearly separate types from runtime code – maksimr Commented Dec 22, 2022 at 16:56
1 Answer
Reset to default 12/**@type {