一位 friend 建议我从 javascript 切换到 Typescript,作为解决我在循环和条件中实现 Promise 时遇到的问题的一种方法(TS 具有异步/等待功能)。我似乎永远无法正确编译 TS。我在 VSCODE 终端上收到的最新错误(与我在控制台上收到的错误集不同)是:
error TS6053: File 'c:/stuff/node_modules/@types/node/index.d.ts' not found.
所以我创建了该目录结构并将 index.d.ts 放入其中,现在我收到以下错误:
node_modules/@types/node/index.d.ts(6,25): error TS2307: Cannot find module 'stream'.
node_modules/@types/node/index.d.ts(14,32): error TS2304: Cannot find name 'Buffer'.
node_modules/@types/node/index.d.ts(15,78): error TS2304: Cannot find name 'Buffer'.
node_modules/@types/node/index.d.ts(23,39): error TS2304: Cannot find name 'Buffer'.
最佳答案
这不是解决问题的正确方法:
created that directory structure and put index.d.ts in there
正确的方法是在 VSCode 终端中通过 npm 命令安装 @types/node
(菜单: View > 集成终端):
npm install @types/node --save-dev
安装之前,最好手动删除“@types”文件夹。
关于node.js - 将 Typescript 与 Nodejs 结合使用 - 找不到 index.d.ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46209795/