|
2 | 2 | title: Consumption |
3 | 3 | layout: docs |
4 | 4 | permalink: /zh/docs/handbook/declaration-files/consumption.html |
5 | | -oneline: "How to download d.ts files for your project" |
| 5 | +oneline: "如何下载 .d.ts 文件以供你的项目使用" |
6 | 6 | --- |
7 | 7 |
|
8 | | -## Downloading |
| 8 | +## 下载 |
9 | 9 |
|
10 | | -Getting type declarations requires no tools apart from npm. |
| 10 | +你只需 npm 即可获取类型声明。 |
11 | 11 |
|
12 | | -As an example, getting the declarations for a library like lodash takes nothing more than the following command |
| 12 | +例如,仅需以下命令即可获得类似 lodash 这样库的声明文件 |
13 | 13 |
|
14 | 14 | ```cmd |
15 | 15 | npm install --save-dev @types/lodash |
16 | 16 | ``` |
17 | 17 |
|
18 | | -It is worth noting that if the npm package already includes its declaration file as described in [Publishing](/zh/docs/handbook/declaration-files/publishing.html), downloading the corresponding `@types` package is not needed. |
| 18 | +值得注意的是,如果 npm 包已经包含其声明文件,如[发布](/zh/docs/handbook/declaration-files/publishing.html)中所述,那么不需要下载相应的 `@types` 包。 |
19 | 19 |
|
20 | | -## Consuming |
| 20 | +## 使用 |
21 | 21 |
|
22 | | -From there you’ll be able to use lodash in your TypeScript code with no fuss. |
23 | | -This works for both modules and global code. |
| 22 | +之后,你就可以在 TypeScript 代码中轻松使用 lodash。这适用于模块和全局代码。 |
24 | 23 |
|
25 | | -For example, once you’ve `npm install`-ed your type declarations, you can use imports and write |
| 24 | +例如,一旦你通过 `npm install` 安装了类型声明,你就可以使用导入并编写 |
26 | 25 |
|
27 | 26 | ```ts |
28 | 27 | import * as _ from "lodash"; |
29 | 28 | _.padStart("Hello TypeScript!", 20, " "); |
30 | 29 | ``` |
31 | 30 |
|
32 | | -or if you’re not using modules, you can just use the global variable `_`. |
| 31 | +或者,如果你不使用模块,你可以直接使用全局变量 `_`。 |
33 | 32 |
|
34 | 33 | ```ts |
35 | 34 | _.padStart("Hello TypeScript!", 20, " "); |
36 | 35 | ``` |
37 | 36 |
|
38 | | -## Searching |
| 37 | +## 搜索 |
39 | 38 |
|
40 | | -For the most part, type declaration packages should always have the same name as the package name on `npm`, but prefixed with `@types/`, |
41 | | -but if you need, you can use the [Yarn package search](https://yarnpkg.com/) to find the package for your favorite library. |
| 39 | +在大多数情况下,类型声明包的名称应与 `npm` 上的包名称相同,但前缀为 `@types/`,但如果需要,你可以使用 [Yarn 包搜索](https://yarnpkg.com/)来查找你喜欢的库的包。 |
42 | 40 |
|
43 | | -> Note: if the declaration file you are searching for is not present, you can always contribute one back and help out the next developer looking for it. |
44 | | -> Please see the DefinitelyTyped [contribution guidelines page](https://definitelytyped.org/guides/contributing.html) for details. |
| 41 | +> 注意:如果你正在搜索的声明文件不存在,你可以随时贡献并帮助下一个寻找它的开发人员。 |
| 42 | +> 请参阅 DefinitelyTyped 的[贡献指南页面](https://definitelytyped.org/guides/contributing.html)以获取详细信息。" |
0 commit comments