VSCODE Javascript ----如何隐式导入库

mox*_*cat 7 javascript visual-studio-code

我想在引用库时隐藏“导入”,即本地/全局导入,正常使用库的内容\n可以实现吗,还是已经实现了?

\n

我在插件加载器中使用这些代码,因此我不需要导入它。它\xe2\x80\x99只是一个提示查看注释的工具。

\n

我正在使用 VSCODE 及其内置 JavaScript

\n

例子:

\n
import { mc } from "./Libary/Game/Player";\n\nmc.runcmd('kill u m')\n
Run Code Online (Sandbox Code Playgroud)\n

想要使用:

\n
mc.runcmd('kill u m')\n
Run Code Online (Sandbox Code Playgroud)\n

并且还可以看到注释和函数类型等。

\n

Dav*_*man 0

通过在文件中声明库的 API并在项目的根目录中.d.ts设置,VSCode 将自动在全局范围内包含这些定义。jsconfig.json

这是一个示例存储库,其功能用法为mc.runcmdhttps://github.dev/david-shortman/vscode-javascript-how-to-implicit-import-library

有关声明文件的更多信息 - https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html

更多信息jsconfig.json- https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#using-tsconfigjson-or-jsconfigjson