簡體   English   中英

如何在打字稿中使用添加的打字

[英]How to use added typings in typescript

我正在嘗試學習Typescript,並在教程之后設置了一個基本的打字稿結構。

我現在需要為項目添加打字。 所以我環顧四周,找到了打字 然后我使用Lodash添加了JQueryLodashD3 我的項目結構如下所示:

├── 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"
    }
}

我的問題是,我該如何添加*.d.ts中的文件,我有typings目錄在我main.ts文件,並開始使用jQuery的$或D3的d3

我注意到index.d.ts文件中的typings ,看起來像這樣:

/// <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 2建議使用npm作為類型。 請參閱聲明文件的未來

您應該需要的是:

npm install --save @types/lodash @types/d3 @types/jquery

並且很高興去。

您可以在tsconfig中添加它:

"files": [
    "src/ts/*.ts",
    "typings/**/*.ts"
]

要不就

"files": [
    "src/ts/*.ts",
    "typings/index.d.ts"
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM