JavaScript 和 TypeScript 支持JavaScript and TypeScript support

Visual Studio for Mac 通过语法突出显示、代码格式设置和 IntelliSense 提供对 JavaScript 和 TypeScript 的支持。Visual Studio for Mac provides support for JavaScript and TypeScript through syntax highlighting, code formatting, and IntelliSense.

typescript 编辑器支持

有关编写 JavaScript 的详细信息,请参阅编写 JavaScript 代码指南。For more information on writing JavaScript, see to the Writing JavaScript Code guides.

添加 JavaScript 文件Adding a JavaScript file

通常通过“新建文件”对话框将 JavaScript 文件添加到 ASP.NET Core 项目****。JavaScript files are most often added to ASP.NET Core projects through the New File dialog. 要添加 javascript 文件,右键单击项目并转到“添加”>“新建文件”****:To add a javascript file, right-click on your project and go to Add > New File:

将新建文件添加到项目中

从“新建文件”对话框选择“Web > 空 JS 文件”或“Web > TypeScript 文件”************。From the New File dialog, select Web > Empty JS file or Web > TypeScript file. 为文件命名,然后选择“新建”****:Give it a name and then choose New:

从模板创建新的 typescript 文件

IntelliSenseIntelliSense

Visual Studio for Mac 使用 JavaScript Language Service 提供 IntelliSense,为用户在编写代码时提供智能代码完成、参数信息和成员列表。Visual Studio for Mac uses the JavaScript Language Service to provide IntelliSense, allowing you to have intelligent code completion, parameter info, and member lists when writing code.

Visual Studio for Mac 中的 JavaScript IntelliSense 可以基于类型推理、JSDoc 或 TypeScript 声明。JavaScript IntelliSense in Visual Studio for Mac can be based on type inference, JSDoc, or TypeScript declarations.

  • 类型推理 - 对象类型是通过周围的代码上下文推出的。Type inference – The type of an object is figured out by the surrounding code context. 有关详细信息,请参阅基于类型推理的 IntelliSense 的 Visual Studio 部分。For more information, see Visual Studio's section on IntelliSense based on type inference.

  • JSDoc - 有时类型推理不提供正确的类型信息。JSDoc – There are times when type inference doesn't provide the correct type information. 在这些情况下,类型信息可以由 JSDoc 注释显式提供。In these cases, the type information can be provided explicitly by JSDoc annotations. 有关详细信息,请参阅基于 JSDoc 的 IntelliSense 的 Visual Studio 部分For more information, see Visual Studio's section on IntelliSense based on JSDoc

  • TypeScript 声明文件 - .d.ts 文件用于提供 JavaScript IntelliSense 的值。TypeScript declaration files.d.ts files are used to provide values for JavaScript IntelliSense. 该文件中声明的类型可用作 JSDoc 注释的类型。Types declared in that file can be used as types on JSDoc comments. 有关详细信息,请参阅基于 TypeScript 声明文件的 IntelliSense 的 Visual Studio 部分For more information, see Visual Studio's section on IntelliSense based on TypeScript declaration files

    添加 typescript 定义文件

另请参阅See also