【发布时间】:2017-02-26 14:01:31
【问题描述】:
我正在尝试学习 Typescript,并按照this 教程建立了一个基本的 typescript 结构。
我现在需要在项目中添加类型。于是我环顾四周,发现typings。然后我使用类型添加了JQuery、Lodash 和D3。我的项目结构如下所示:
├── dist
│ ├── chart.js
│ ├── greet.js
│ └── main.js
├── gulpfile.js
├── package.json
├── src
│ └── ts
│ ├── chart.ts
│ ├── greet.ts
│ └── main.ts
├── tsconfig.json
├── typings
│ ├── globals
│ │ └── jquery
│ │ ├── index.d.ts
│ │ └── typings.json
│ ├── index.d.ts
│ └── modules
│ ├── d3
│ │ ├── index.d.ts
│ │ └── typings.json
│ └── lodash
│ ├── index.d.ts
│ └── typings.json
└── typings.json
这是我的tsconfig.json 文件:
{
"files": [
"src/ts/*.ts"
],
"compilerOptions": {
"noImplicitAny": true,
"target": "es5"
}
}
我的问题是,如何在我的main.ts 文件中添加我在typings 目录中的*.d.ts 文件并开始使用jQuery 的$ 或D3 的d3?
我注意到typings 中的index.d.ts 文件看起来像这样:
/// <reference path="globals/jquery/index.d.ts" />
/// <reference path="modules/d3/index.d.ts" />
/// <reference path="modules/lodash/index.d.ts" />
所以我的猜测是,我只需将此文件添加到我的 main.ts 文件或 tsconfig.json 文件中的某个位置(而不是手动添加每个 .d.ts 文件)。我对吗?谢谢。
【问题讨论】:
标签: typescript typescript-typings