It appears that the behavior of VS Code in relation to JavaScript validation is quite specific. According to observations made in comments, it seems that for JavaScript validation to occur, along with setting the html.validate.scripts
configuration in VS Code to true
, the first block of JavaScript code within the HTML document must begin with a @ts-check
directive comment.
To delve deeper into understanding how this process works within VS Code, one can refer to the source code and trace through various sections:
The interesting aspect here revolves around the implementation of script-valued attributes and the usage of the getEmbeddedDocument
function defined in embeddedSupport.ts. Notably, there exists an optional parameter named ignoreAttributeValues
that remains unutilized in the current context.
In order to ensure successful execution of JS checking alongside script-valued attributes, it is advised to include a script
element early in the HTML file, preferably placed near the top within the head
element, containing a @ts-check
directive comment like so:
<script>//@ts-check</script>
.
Additional information on TypeScript's recognition of the @ts-check
directive can be found at this resource, specifying that the directive must reside at the commencement of a JavaScript file for proper detection.