简体   繁体   English

VSCode Typescript 自动导入

[英]VSCode Typescript Autoimport

I do not expect VSCode to work flawlessly for other programming languages.我不希望 VSCode 能够完美地适用于其他编程语言。 But it always seemed like it has great support for typescript.但它似乎总是对 typescript 有很好的支持。 But it does not work so well for me.但这对我来说效果不佳。 I do not know if something is configured wrong or if I am missing something.我不知道是否配置错误或者我是否遗漏了什么。

The biggest problem I have is with the auto import.我遇到的最大问题是自动导入。 When I try to import for example an angular module, it does not work unless I manually import it once with import {} from '@angular/router' at the top.例如,当我尝试导入 angular 模块时,它不起作用,除非我在顶部使用import {} from '@angular/router'手动导入一次。 Then VSCode find all modules in the router package.然后VSCode找到路由器package中的所有模块。 Is this supposed to work that way?这应该这样工作吗?

Another problem is that auto complete suggestion are really slow.另一个问题是自动完成建议真的很慢。 While I am typing VSCode just freezes for 1 or 2 seconds and then it show the auto complete suggestions.当我输入 VSCode 时,它会冻结 1 或 2 秒,然后它会显示自动完成建议。

This is in my tsconfig.json if this is of any help.如果有任何帮助,这在我的tsconfig.json中。

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2017", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
  },
  "exclude": ["node_modules", "tmp"]
}

Does anyone else have these problems?其他人有这些问题吗? Or does anyone know how to solve these?或者有谁知道如何解决这些问题?

Edit: More info of my system编辑:我的系统的更多信息

OS: Manjaro 5.4.44-1操作系统:Manjaro 5.4.44-1

VSCode: v1.47.0 VSCode:v1.47.0

Typescript: 4.0.0-dev.20200710 Typescript:4.0.0-dev.20200710

I am sure there is no issue in your ts configuration.... it must be something with VSCode software only... Do one thing upgrade your VSCode software and also install some third party extension to support Auto intelligence.... In my case I have installed TSLINT and it's working great我确定您的 ts 配置没有问题....它必须仅与 VSCode 软件有关...做一件事升级您的 VSCode 软件并安装一些第三方扩展以支持自动智能....在我的案例我已经安装了 TSLINT,它工作得很好

Couple of things that I found out after long research经过长时间的研究,我发现了几件事

The freezes on auto complete only happens with the "Javascript and Typescript Nightly" extension enabled.自动完成时的冻结仅在启用“Javascript 和 Typescript Nightly”扩展时发生。

And the problem with auto import is just not working There is this issue on github #37812 that was just closed recently.自动导入的问题只是不起作用最近刚刚关闭的 github #37812上有这个问题。 It should fix the auto import for modules that have their own location for the @types files like angular material does.它应该修复对于@types文件(如 angular 材料)具有自己位置的模块的自动导入。 It should be in the typescript 4.0 release.它应该在 typescript 4.0 版本中。 So I just have to wait.所以我只需要等待。

Had this issue as well, VSCode auto-import suggestions freezed, just worked once on the editor startup and then stopped.也有这个问题,VSCode 自动导入建议冻结,只在编辑器启动时工作一次,然后停止。

Disabling the "Javascript and Typescript Nightly" extension fixed this problem, as @Sakkaku mentioned.正如@Sakkaku 所提到的,禁用“Javascript 和 Typescript Nightly”扩展解决了这个问题。

For those who are experiencing vs code auto-import issues, it could be likely that your Javascript/Typescript IntelliSense is not working properly because of missing TypeScript and JavaScript Language Features对于那些遇到 vs 代码自动导入问题的人,您的 Javascript/Typescript IntelliSense 可能由于缺少TypeScript 和 JavaScript 语言功能而无法正常工作

at Extensions tab and search: @builtin TypeScript and JavaScript Language Features, and enable it.在扩展选项卡和搜索:@builtin TypeScript 和 JavaScript 语言功能,并启用它。

I solved my issue by enabling it.我通过启用它解决了我的问题。 Screenshot of the extension reference link: Visual Studio Code autocomplete/IntelliSense not working properly for JavaScript扩展参考链接的屏幕截图Visual Studio Code autocomplete/IntelliSense not working normal for JavaScript

JUST use the Auto Import extension in your VScode editor.只需在 VScode 编辑器中使用自动导入扩展。 by writing the name of the module automatically import them at the top of the page.通过编写模块的名称自动将它们导入页面顶部。 you can even find the link here你甚至可以在这里找到链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM