简体   繁体   English

Visual Studio Code 中的 .ts 文件没有智能感知

[英]No intellisense for .ts files in Visual Studio Code

I'm running Visual Studio Code 1.17.2 on Arch Linux to get started on Node.js/Angular4.我正在 Arch Linux 上运行 Visual Studio Code 1.17.2 以开始使用 Node.js/Angular4。 To avoid mess caused by loosely types, I want to use TypeScript on the NodeJS server, too.为了避免松散类型造成的混乱,我也想在 NodeJS 服务器上使用 TypeScript。 So my main file is called server.ts .所以我的主文件被称为server.ts

The problem: I don't get intellisense on external packages like express or socket.io.问题:我没有得到像 express 或 socket.io 这样的外部包的智能感知。 For example, when I type require('express').例如,当我输入require('express'). there is no list with suggestions for methods.没有列出方法建议。 This seems caused by the extension: After renaming server.ts to server.js it works fine (typings were already installed using npm).这似乎是由扩展引起的:将server.ts重命名为server.js它工作正常(已使用 npm 安装了类型)。

As my file is TypeScript and no JavaScript, I would like to use the correct .ts extension instead of .js .由于我的文件是 TypeScript 而没有 JavaScript,我想使用正确的.ts扩展名而不是.js But how can I make intellisense work based on .ts extension?但是如何基于.ts扩展名使智能感知工作?

Visual studio code include TypeScript language but does not include the TypeScript compiler, tsc. Visual Studio 代码包括 TypeScript 语言但不包括 TypeScript 编译器 tsc。 To use it in visual Studio Code, you will have to install it manually.要在 Visual Studio Code 中使用它,您必须手动安装它。 One way to do this is by the following command :一种方法是通过以下命令:

npm install -g typescript

After added the tsc compiler, you should get the correct intellisense for Typescript in Visual studio code.添加 tsc 编译器后,您应该在 Visual Studio 代码中获得正确的 Typescript 智能感知。 To go forward with the typescript in visual studio code i advice you to read the following link : https://code.visualstudio.com/docs/languages/typescript要继续使用 Visual Studio 代码中的打字稿,我建议您阅读以下链接: https : //code.visualstudio.com/docs/languages/typescript

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

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