简体   繁体   中英

Define context of JS script in IntelliJ IDEA/WebStorm

I use IntelliJ to write JS scripts that are executed in an environment where several context variables are set implicitly, eg embeddingPage .
But IntelliJ does not know about the context so it marks these variables as unknown:

Unresolved variable or type embeddingPage

Additionally the script execution requires to return a config object at the end that the IDE complains about:

'return' outside function definition

Is there a way to make the context known to the IDE without breaking the execution of the script?

You can let the IDE know about your implicitly set variables by adding JSDoc annotations somewhere in your code. The @name tag seems to be the best choice as it is typically used in "virtual comments" for symbols that are not readily visible in the code, such as methods that are generated at runtime.

As for "'return' outside function definition" error, I can only suggest disabling the JavaScript and TypeScript | General | ECMAScript specification is not followed inspection or suppressing it for statement using // noinspection JSAnnotator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM