Adding JavaScript type hints for VSCode/Monaco Intellisence

那年仲夏 提交于 2019-11-30 22:30:35

Update: As of 0.9.0 of Monaco these type annotations now work


Is see that JSDoc style type annotations work in VSCode though they don't appear to work in Monaco.

var loc = window.location;

/** @type {WebGLRenderingContext} */
var gl = context1.getContext("webgl");    

/** @type {CanvasRenderingContext2D} */
var ctx = context2.getContext("2d"); 

As Micah pointed out in a comment on the accepted answer, there can still be issues with external modules. Simply doing a require of the module will already enable jsdoc type annotations to work if the library defines a global object from which you can reference the types. Otherwise, you can mimic this by importing everything and mapping it to your own name.

import * as Foo from 'foo'

/** @type {Foo.Foo} */
var foo;

https://github.com/Microsoft/TypeScript/issues/8237#issuecomment-213047062

If you are willing to use Typescript, you can do this:

var gl : WebGLRenderingContext;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!