如何在 VS Code 中为 Backbone 启用 IntelliSense
How to enable IntelliSense for Backbone in VS Code
我正在尝试为示例 Backbone.js 项目安装 TypeScript 定义。
在项目目录中,我发出了以下命令:
npm init
npm install typings
typings install dt~backbone --global
这会将 index.d.ts
和 typings.json
文件添加到 \typings\globals\backbone
文件夹。
控制台输出如下:
如图所示,每个文件大小为 1 KB,VS Code 智能感知不会获取任何 Backbone 定义。 (项目文件夹确实包含一个 jsconfig.json 文件。)
"typings install dt~backbone..." 命令不应该安装实际的 backbone 类型定义(在 backbone-global.d.ts
(17 KB) 中找到),以及下划线和 jquery 等依赖项(每个大约 140 KB)? stripped reference
是否表示某种类型的错误?
如何安装这些 files/definitions(以便 VS Code intellisense 正常工作)?
前言
引用总是从 Typings 安装中删除,因为它们的性质不明确。 Backbone definitions file doesn't contain the definitions and just references backbone-global and underscore. There is an open issue 关于这个。
安装和配置
默认情况下,所有在Visual Studio代码中打开的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
文件的依赖项部分,但对于打字管理器。
例子
我刚刚对此进行了快速测试,IntelliSense 在安装了所有引用的定义并创建了 jsconfig.json
文件后似乎可以正常工作。
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" />
我正在尝试为示例 Backbone.js 项目安装 TypeScript 定义。
在项目目录中,我发出了以下命令:
npm init
npm install typings
typings install dt~backbone --global
这会将 index.d.ts
和 typings.json
文件添加到 \typings\globals\backbone
文件夹。
控制台输出如下:
如图所示,每个文件大小为 1 KB,VS Code 智能感知不会获取任何 Backbone 定义。 (项目文件夹确实包含一个 jsconfig.json 文件。)
"typings install dt~backbone..." 命令不应该安装实际的 backbone 类型定义(在 backbone-global.d.ts
(17 KB) 中找到),以及下划线和 jquery 等依赖项(每个大约 140 KB)? stripped reference
是否表示某种类型的错误?
如何安装这些 files/definitions(以便 VS Code intellisense 正常工作)?
前言
引用总是从 Typings 安装中删除,因为它们的性质不明确。 Backbone definitions file doesn't contain the definitions and just references backbone-global and underscore. There is an open issue 关于这个。
安装和配置
默认情况下,所有在Visual Studio代码中打开的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
文件的依赖项部分,但对于打字管理器。
例子
我刚刚对此进行了快速测试,IntelliSense 在安装了所有引用的定义并创建了 jsconfig.json
文件后似乎可以正常工作。
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" />