以下代码是从
nest g res users
生成的。
在 VS Code 中添加
BadRequestException
时,重构功能 (Ctrl + .
) 工作正常,但自动完成功能不行。它不会自动完成名称,需要使用 Ctrl + .
添加导入语句。
相同的自动完成功能在 PyCharm 2023.1.2 中运行良好。它会自动完成名称并添加导入语句。
我认为我的 VSCode 正确识别了 node_modules 路径,因为重构功能工作正常。但我不知道为什么自动完成功能不起作用。 :(
我在 VS Code 中启用了以下功能。
对于 VS Code 中更好的 JS/TS 自动完成有什么建议吗?
目前,我在 VS Code 中使用
"typescript.suggest.enabled": true
。
这是我的
npm list
。
@nestjs/[email protected]
@nestjs/[email protected]
@nestjs/[email protected]
@nestjs/[email protected]
@nestjs/[email protected]
@nestjs/[email protected]
@nestjs/[email protected]
@types/[email protected]
@types/[email protected]
@types/[email protected]
@types/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
// Select npm for package manager
> nest new project
> cd project
// Select REST API and generate CRUD entry points
> nest g res users
> code .
在文件中
project/src/users/users.controller.ts
:
...
@Get(':id')
findOne(@Param('id') id: string) {
// Here is the problem, cannot find `BadRequestException`
if (+id > 1) {
throw new BadReq<autocomplete>
}
return this.usersService.findOne(+id);
}
...
为了找到问题的原因,我尝试了一些方法。
首先我尝试在 MacOS Ventura 上重现该问题,但问题并未发生。
接下来,我在新的 Windows 实例上尝试了此操作,但也无法重现该问题。
所以我回到我的开发环境并完全删除 VS Code 并重新安装它。这根本没有帮助。
最后,我删除并重新安装了 npm。之后问题就消失了。
我无法弄清楚问题的原因是什么。 但在某些情况下,重新安装 npm 可以解决 VS Code 上的自动完成问题。
我也有同样的问题。我发现它是 npm Intellisense,所以我禁用它,它工作正常。