Adding JavaScript type hints for VSCode/Monaco Intellisence
<p>Is there a way to hint to VSCode/Monaco's intellisense the types of variables.</p>

<p>I have some code like this</p>

<pre><code>var loc = window.location;
var gl = context1.getContext("webgl");
var ctx = context2.getContext("2d");
</code></pre>

<p>I see that VSCode knows that <code>loc</code> is a <code>URL</code></p>

<p><a href="https://i.stack.imgur.com/K9WWd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/K9WWd.png" alt="vscode knows loc"></a></p>

<p>But it doesn't know what <code>gl</code> is</p>

<p><a href="https://i.stack.imgur.com/wPyI9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wPyI9.png" alt="vscode does not know gl"></a></p>

<p>Nor does it know what <code>ctx</code> is</p>

<p><a href="https://i.stack.imgur.com/Oz6e8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Oz6e8.png" alt="vscode does not know ctx"></a></p>

<p>Which makes sense, having a function return different types based on its input is a somewhat unusual case.</p>

<p>But it does have type data for <code>WebGLRenderingContext</code></p>

<p><a href="https://i.stack.imgur.com/LDttb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LDttb.png" alt="vscode knows webglrenderingcontext"></a></p>

<p>and it knows <code>CanvasRenderingContext2D</code></p>

<p><a href="https://i.stack.imgur.com/elixV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/elixV.png" alt="vscode knows canvasrenderingcontext2d"></a></p>

<p>Is there a way to for me to tell vscode/monaco that <code>gl</code> is an instance of <code>WebGLRenderingContext</code> and that <code>ctx</code> is an instance of <code>CanvasRenderingContext2D</code> without having to switch to typescript? Maybe by adding some kind of comment?</p>

<p>I need the solution to work in <a href="https://microsoft.github.io/monaco-editor/" rel="noreferrer">monaco</a> (which at least in my tests shows all the same completions) because this is for a WebGL tutorial site, not actually for VSCode but I'm hoping the solution is the same. </p>