我是 TypeScript 的新手,如果这是基本的,很抱歉。
我目前正在 IntelliJ IDEA 2020 中开发一个小型 typescript webapp。我希望它完全在浏览器中运行,我相信这意味着除了编译成 JavaScript 之外,我不能使用 Node 来做任何事情。我还想使用一些外部依赖项,例如 JQuery 和 Plotly,它们可以通过 NPM 以及 CDN 获得,并且具有.d.ts
声明文件。
不幸的是,如果没有 IntelliJ 在编辑器中抱怨、TypeScript 无法编译和/或我的浏览器在尝试运行已编译的 JavaScript 时抛出错误,我无法弄清楚如何使用这些依赖项。现在我得到了前两个:Plotly 是红色的(“找不到名称'Plotly'。”)并且有一个黄色的下划线(“对 UMD 全局的引用”)。我已经下载plotly-latest
并@types/plotly.js
在 Settings > Languages & Frameworks > JavaScript > Libraries 中添加plotly.js
了 Settings > Languages & Frameworks > Node.js 和 NPM,并直接将.d.ts
文件包含在tsconfig.json
. 我错过了什么?
这是我的tsconfig.json
样子(我正在使用 AMD 让我将我的源文件相互导入,但如果我做错了,或者我应该在那里放其他东西,请告诉我):
{
"compilerOptions": {
"lib": ["ES2016", "DOM"],
"allowJs": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"noEmitOnError": true,
"module": "AMD",
"outFile": "./build/build.js"
},
"include": [
"src/*",
"../../../.IntelliJIdea2019.3/config/javascript/extLibs/global-types/node_modules/@types/jquery/misc.d.ts",
"../../../.IntelliJIdea2019.3/config/javascript/extLibs/global-types/node_modules/@types/tinyqueue/index.d.ts",
"../../../.IntelliJIdea2019.3/config/javascript/extLibs/global-types/node_modules/@types/plotly.js/lib/index.d.ts"
]
}