Skip to content

Commit 2285d34

Browse files
committed
init translation of module.plugin.d.ts
1 parent ac7c94e commit 2285d34

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

docs/documentation/zh/declaration-files/templates/module-plugin.d.ts.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,62 @@ layout: docs
44
permalink: /zh/docs/handbook/declaration-files/templates/module-plugin-d-ts.html
55
---
66

7-
For example, when you want to work with JavaScript code which extends another library.
7+
例如,当你想要使用扩展另一个库的 JavaScript 代码时。
88

99
```ts
1010
import { greeter } from "super-greeter";
1111

12-
// Normal Greeter API
12+
// 正常的问候 API
1313
greeter(2);
1414
greeter("Hello world");
1515

16-
// Now we extend the object with a new function at runtime
16+
// 现在我们在运行时用一个新函数扩展对象
1717
import "hyper-super-greeter";
1818
greeter.hyperGreet();
1919
```
2020

21-
The definition for "super-greeter":
21+
对于“super-greeter”的定义:
2222

2323
```ts
24-
/*~ This example shows how to have multiple overloads for your function */
24+
/*~ 此示例展示了如何让函数有多个重载 */
2525
export interface GreeterFunction {
2626
(name: string): void
2727
(time: number): void
2828
}
2929

30-
/*~ This example shows how to export a function specified by an interface */
30+
/*~ 此示例展示了如何导出由接口指定的函数 */
3131
export const greeter: GreeterFunction;
3232
```
3333

34-
We can extend the existing module like the following:
34+
我们可以像下面这样扩展现有模块:
3535

3636
```ts
37-
// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~]
38-
// Project: [~THE PROJECT NAME~]
39-
// Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>
37+
// 类型定义为 [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~]
38+
// 项目: [~THE PROJECT NAME~]
39+
// 定义者: [~YOUR NAME~] <[~A URL FOR YOU~]>
4040

41-
/*~ This is the module plugin template file. You should rename it to index.d.ts
42-
*~ and place it in a folder with the same name as the module.
43-
*~ For example, if you were writing a file for "super-greeter", this
44-
*~ file should be 'super-greeter/index.d.ts'
41+
/*~ 这是模块插件模板文件。你应该将其重命名为 index.d.ts
42+
*~ 并将其放在与模块同名的文件夹中。
43+
*~ 例如,如果你为 "super-greeter" 编写一个文件,此
44+
*~ 文件应该是 'super-greeter/index.d.ts'
4545
*/
4646

47-
/*~ On this line, import the module which this module adds to */
47+
/*~ 在此行上,导入此模块添加的模块 */
4848
import { greeter } from "super-greeter";
4949

50-
/*~ Here, declare the same module as the one you imported above
51-
*~ then we expand the existing declaration of the greeter function
50+
/*~ 在此处,声明与上面导入的模块相同的模块
51+
*~ 然后我们扩展 greeter 函数的现有声明
5252
*/
5353
export module "super-greeter" {
5454
export interface GreeterFunction {
55-
/** Greets even better! */
55+
/** 更好的问候! */
5656
hyperGreet(): void;
5757
}
5858
}
5959
```
6060

61-
This uses [declaration merging](/zh/docs/handbook/declaration-merging.html)
61+
这使用了[声明合并](/zh/docs/handbook/declaration-merging.html)
6262

63-
## The Impact of ES6 on Module Plugins
63+
## ES6 对模块插件的影响
6464

65-
Some plugins add or modify top-level exports on existing modules.
66-
While this is legal in CommonJS and other loaders, ES6 modules are considered immutable and this pattern will not be possible.
67-
Because TypeScript is loader-agnostic, there is no compile-time enforcement of this policy, but developers intending to transition to an ES6 module loader should be aware of this.
65+
有些插件在现有模块上添加或修改顶级导出。虽然这在 CommonJS 和其他加载器中是合法的,但 ES6 模块被认为是不可变的,这种模式将不再可能。由于 TypeScript 是与加载器无关的,因此没有编译时强制执行此策略,但打算迁移到 ES6 模块加载器的开发人员应该注意这一点。

0 commit comments

Comments
 (0)