Neu*_*ino 5 node.js typescript visual-studio-code
当我使用 Typescript 创建新的 Node 项目时,VsCode 自动导入建议根本不起作用。
重现步骤:
创建工作区目录。
运行npm init指定main.ts为入口点文件。
导入 typescript clinpm i typescript
创建 tsconfig.json.\node_modules\.bin\tsc --init
创建 main.ts 包含console.log('Running');
转译使用.\node_modules\.bin\tsc -w
Debug通过单击VsCode 并使用默认的 Nodejs 启动配置来运行。
导入库,例如 Rxjs 导入 typescript clinpm i rxjs
结果:
在 main.ts 中尝试使用任何 Rxjs 类型Observable、BehaviourSubject全局运算符from of sequenceEqual等都不会产生任何导入帮助。
我已阅读 VsCode Typescript 文档,没有任何迹象表明出了什么问题。https://code.visualstudio.com/docs/languages/typescript
我尝试在 tsconfig.json 中显式设置include和exclude目录,但这也没有效果。
我需要在 tsconfig 中手动设置一些模块解析选项吗?
我不知道,我不知道为什么这不起作用。
更新:
我设法通过指定使 VsCode 自动导入工作
"typeRoots": [ "node_modules" ]
Run Code Online (Sandbox Code Playgroud)
...在 tsconfig.json 中
结果出现一个小问题,即 tsc 现在报告错误
error TS2688: Cannot find type definition file for '.bin'.
Run Code Online (Sandbox Code Playgroud)
看来 tsc 现在尝试读取 node_modules.bin 的内容,这没有帮助。我尝试过设置
"exclude": [ "./node_modules/.bin"]
Run Code Online (Sandbox Code Playgroud)
在 tsconfig 中,但这没有效果。
尝试给予main.js作为你的切入点不main.ts
我遵循的步骤:
创建工作区目录。
运行 npm init 并指定index.js为入口点文件。
安装 typescript cli:npm i typescript
创建 tsconfig.json:.\node_modules\.bin\tsc --init
创建包含以下内容的index.tsconsole.log('Running');
转译使用.\node_modules\.bin\tsc -w
通过在 VSCode 中单击“调试”并使用默认的 Nodejs 启动配置来运行。
安装一个库,例如 Rxjs: npm i rxjs
现在在index.ts文件中:import { observable, BehaviorSubject } from "rxjs";
我能够得到那些 IntelliSense(导入帮助)
| 归档时间: |
|
| 查看次数: |
2840 次 |
| 最近记录: |