简体   繁体   中英

VSCODE Javascript ----how to Implicit import library

I want to hide "import" when referencing the library, that is, local/global import, and use the contents of the library normally Can it be achieved, or is it already achieved?

I use these codes in a plug-in loader, so I don't need to import it. It's just a tool for prompting to view annotations.

I am using VSCODE and its built-in JavaScript

example:

import { mc } from "./Libary/Game/Player";

mc.runcmd('kill u m')

want to use:

mc.runcmd('kill u m')

And you can also see comments and function types, etc.

I don't think this is achievable at the moment nor do I think it should be, because:

It is not possible in vscode, this feature was introduced in one of the versions of IntelliJ IDEA but they had to roll back to the previous version within 2 weeks. It causes too much trouble for programmers. It became really hard to separate two programs from each other and apart from that the size of the build file keeps on increasing with every new project.
If you still want to do that use the idea shared by @David shortman

By declaring the API for your libraries in a .d.ts file and setting up a jsconfig.json in the root of your project, VSCode will automatically include those definitions in the global scope.

Here's an example repository with a functioning usage of mc.runcmd : https://github.dev/david-shortman/vscode-javascript-how-to-implicit-import-library

More information on declaration files- https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html

More on jsconfig.json - https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#using-tsconfigjson-or-jsconfigjson

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