

The ctx variable will be the type of CanvasRenderingContext2D and the IntelliSense should now work for both of the VS Code and Visual Studio IDE. var canvas = document.createElement('canvas') So, in HTML code, we remove or comment out the canvas element: Īnd then, we create the element in JavaScript and append it into the element. Solution 2 - Create Canvas Element using JavaScriptĪnother solution that also works is instead of getting canvas element from the document.getElementById() method, we create canvas element using JavaScript document.createElement() method. Note: Aside from " 2d", there are three other argument values for the getContext() method. This is due to the " 2d" ContextType argument when calling getContext("2d") method in line 3. If we now try to type ctx., the IntelliSense should now be able to detect it contains the drawing context on the canvas and provide code completion for the CanvasRenderingContext2D. The JSDoc comment in the example above lets IntelliSense know that the canvas variable contains the HTMLCanvasElement type.

Var canvas = document.getElementById("canvas") For our purposes, we can use the JSDoc type to let the IntelliSense know the type of the canvas variable. Inside the comments, we can use JSDoc tags that provide additional information about the code. The JSDoc comment must begin with /** and end with */ and it refers to JavaScript code that immediately follows that comment. It is most commonly used to document the API of JavaScript libraries. JSDoc is a JavaScript API documentation tool that allows us to document JavaScript source code using comments.

Solution 1 - Help IntelliSense know the type by using JSDoc The solutions are the same for both VS Code and Visual Studio IDE. IntelliSense is unable to determine the accuracy of this completion item.
