Skip to content

Commit 3ba512f

Browse files
committed
init translation of module function d ts
1 parent 65f0a2e commit 3ba512f

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

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

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
---
2-
title: "Module: Function"
2+
title: "模块: 函数"
33
layout: docs
44
permalink: /zh/docs/handbook/declaration-files/templates/module-function-d-ts.html
55
---
66

7-
For example, when you want to work with JavaScript code which looks like:
7+
# 模块: 函数
8+
9+
当你想处理如下 JavaScript 代码时:
810

911
```ts
1012
import greeter from "super-greeter";
@@ -13,56 +15,53 @@ greeter(2);
1315
greeter("Hello world");
1416
```
1517

16-
To handle both importing via UMD and modules:
18+
为了同时支持 UMD 和模块导入,你可以使用以下模板:
1719

1820
```ts
19-
// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~]
20-
// Project: [~THE PROJECT NAME~]
21-
// Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]>
21+
// [~库名称~] [~可选版本号~] 的类型定义
22+
// 项目: [~项目名称~]
23+
// 定义者: [~你的姓名~] <[~你的网址~]>
2224

23-
/*~ This is the module template file for function modules.
24-
*~ You should rename it to index.d.ts and place it in a folder with the same name as the module.
25-
*~ For example, if you were writing a file for "super-greeter", this
26-
*~ file should be 'super-greeter/index.d.ts'
25+
/*~ 这是函数模块的模块模板文件。
26+
*~ 你应该将其重命名为 index.d.ts 并将其放在与模块同名的文件夹中。
27+
*~ 例如,如果你为 "super-greeter" 编写文件,则
28+
*~ 此文件应为 'super-greeter/index.d.ts'
2729
*/
2830

29-
// Note that ES6 modules cannot directly export class objects.
30-
// This file should be imported using the CommonJS-style:
31-
// import x = require('[~THE MODULE~]');
31+
// 注意,ES6 模块无法直接导出类对象。
32+
// 此文件应使用 CommonJS 风格导入:
33+
// import x = require('[~模块~]');
3234
//
33-
// Alternatively, if --allowSyntheticDefaultImports or
34-
// --esModuleInterop is turned on, this file can also be
35-
// imported as a default import:
36-
// import x from '[~THE MODULE~]';
35+
// 或者,如果启用了 --allowSyntheticDefaultImports 或
36+
// --esModuleInterop,可以将此文件作为默认导入:
37+
// import x from '[~模块~]';
3738
//
38-
// Refer to the TypeScript documentation at
39+
// 请参阅 TypeScript 文档了解
3940
// https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
40-
// to understand common workarounds for this limitation of ES6 modules.
41+
// 以了解此 ES6 模块限制的常见解决方法。
4142

42-
/*~ If this module is a UMD module that exposes a global variable 'myFuncLib' when
43-
*~ loaded outside a module loader environment, declare that global here.
44-
*~ Otherwise, delete this declaration.
43+
/*~ 如果该模块是一个 UMD 模块,当在模块加载器环境之外加载时
44+
*~ 会暴露一个全局变量 'myFuncLib',在此处声明该全局变量。
45+
*~ 否则,请删除此声明。
4546
*/
4647
export as namespace myFuncLib;
4748

48-
/*~ This declaration specifies that the function
49-
*~ is the exported object from the file
50-
*/
49+
/*~ 此声明指定函数是从文件中导出的对象 */
5150
export = Greeter;
5251

53-
/*~ This example shows how to have multiple overloads for your function */
52+
/*~ 该示例显示如何为函数定义多个重载 */
5453
declare function Greeter(name: string): Greeter.NamedReturnType;
5554
declare function Greeter(length: number): Greeter.LengthReturnType;
5655

57-
/*~ If you want to expose types from your module as well, you can
58-
*~ place them in this block. Often you will want to describe the
59-
*~ shape of the return type of the function; that type should
60-
*~ be declared in here, as this example shows.
56+
/*~ 如果你还想暴露模块中的类型,可以
57+
*~ 将它们放在此块中。通常你会想描述
58+
*~ 函数的返回类型的形状;该类型应
59+
*~ 在这里声明,如此示例所示。
6160
*~
62-
*~ Note that if you decide to include this namespace, the module can be
63-
*~ incorrectly imported as a namespace object, unless
64-
*~ --esModuleInterop is turned on:
65-
*~ import * as x from '[~THE MODULE~]'; // WRONG! DO NOT DO THIS!
61+
*~ 注意,如果你决定包含此命名空间,模块可能会
62+
*~ 被错误地作为命名空间对象导入,除非
63+
*~ 启用了 --esModuleInterop
64+
*~ import * as x from '[~模块~]'; // 错误!不要这样做!
6665
*/
6766
declare namespace Greeter {
6867
export interface LengthReturnType {
@@ -74,8 +73,8 @@ declare namespace Greeter {
7473
lastName: string;
7574
}
7675

77-
/*~ If the module also has properties, declare them here. For example,
78-
*~ this declaration says that this code is legal:
76+
/*~ 如果模块还有属性,请在此声明。例如,
77+
*~ 此声明表示以下代码是合法的:
7978
*~ import f = require('super-greeter');
8079
*~ console.log(f.defaultName);
8180
*/

0 commit comments

Comments
 (0)