WebStorm Code Assistance For Global Variables

不想你离开。 提交于 2020-01-15 01:25:31

问题


I'm working with WebStorm and Parse / Parse-Sever, but having an issue where code assistance is not working the Parse functions. It tells me

require() call is missing

for the Parse variable, but since Parse is defined globally, when I add the require, it overwrites the global variable and breaks things.

Is there a way in WebStorm to enable code assistance for global variables?


回答1:


When using libraries that define their own global symbols, it is recommended that you add the corresponding TypeScript type definition file as a JavaScript library in Preferences | Languages & Frameworks | JavaScript | Libraries. Click Download and search for the library you're using.




回答2:


Additionally to Ekaterina's answer. If you have defined globally PropTypes = require('prop-types'); via webpack provide plugin for example, you can't just add library from node_modules/prop-types/index.js because it doesn't define any global variables except module.exports that doesn't help.

In this case you can create separate file

globals.js
window.PropTypes = require('prop-types')

and add it as Ekaterina sayed to Preferences | Languages & Frameworks | JavaScript | Libraries

P.S. You don't need to import this file in any place of your code if have already set up webpack provide plugin. This file is just to show this global variables for IDE.



来源:https://stackoverflow.com/questions/38978155/webstorm-code-assistance-for-global-variables

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