intellisense - 如何在 VS Code 中为 Backbone 启用 IntelliSense

标签 intellisense visual-studio-code typescript-typings

我正在尝试为示例 Backbone.js 项目安装 TypeScript 定义。

在项目目录中,我发出了以下命令:

npm init
npm install typings
typings install dt~backbone --global

这增加了一个 index.d.ts和一个 typings.json文件到 \typings\globals\backbone文件夹。

enter image description here

控制台输出如下:

enter image description here

如图所示,每个文件都是 1 KB,VS Code 智能感知不会获取任何 Backbone 定义。 (项目文件夹确实包含一个 jsconfig.json 文件。)

“typings install dt~backbone...”命令是否应该不安装实际的 Backbone 类型定义(在 backbone-global.d.ts (17 KB) 中找到),以及下划线和 jquery 等依赖项(每个大约 140 KB)? stripped reference指示某种类型的错误?

如何安装这些文件/定义(以便 VS Code intellisense 正常工作)?

最佳答案

前言

由于其模棱两可的性质,引用总是从 Typings 安装中删除。 Backbone definitions文件不包含定义,仅引用 backbone-global 和下划线。有一个开放的issue关于这个。

安装和配置

默认情况下,在 Visual Studio Code 中打开的所有 JavaScript 文件都被视为独立的单元。如果要为整个项目启用 IntelliSense,请记住将 jsconfig.json 文件(可以为空)放在项目的根目录下。

要安装 Typings 管理器,请执行 npm install typings --global,然后使用以下命令安装具有依赖项的 Backbone 定义:

typings install dt~underscore dt~backbone dt~backbone-global --global

您还可以添加 --save 标志来创建 typings.json 文件。它类似于 package.json 文件的依赖项部分,但用于打字管理器。

示例

我刚刚对此进行了快速测试,在安装所有引用的定义并创建 jsconfig.json 文件后,IntelliSense 似乎可以正常工作。

enter image description here

jsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules",
        "tmp"
    ]
}

typings/index.d.ts

/// <reference path="globals/backbone-global/index.d.ts" />
/// <reference path="globals/backbone/index.d.ts" />
/// <reference path="globals/underscore/index.d.ts" />

关于intellisense - 如何在 VS Code 中为 Backbone 启用 IntelliSense,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38907000/

相关文章:

autocomplete - Atom 中的纯文本自动完成 (Github)

Typescript 将函数参数匹配到类型映射的键和值

typescript /Hapi : Property 'example' does not exist on type 'PluginProperties'

TypeScript:可选的合并类型

vb.net - 如何在 VB.NET for Visual Studio 2015 中显示片段?

visual-studio - 在 VB 中输入时,如何使智能感知上的 Enter 键以与 Visual Studio 中的 C# 相同的方式使用react?

.net - 卸载 CodeRush 和 ReSharper - Intellisense 不起作用

git - 无法克隆存储库 : git@gitlab. com : Permission denied (publickey, 键盘交互)

git - VS Code远程容器:容器中的开放存储库

typescript - 在vscode中使用oclif,如何解决 "The inferred type of ' flags'无法在没有引用的情况下命名...”问题?