Skip to content

Commit 5d19278

Browse files
committed
feat: translate zh
1 parent 67d341e commit 5d19278

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

docs/documentation/zh/reference/Utility Types.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 多功能类型
2+
title: 工具类型
33
layout: docs
44
permalink: /zh/docs/handbook/utility-types.html
55
oneline: TypeScript 中全局包含的类型
@@ -119,6 +119,8 @@ todo.title = "Hello";
119119

120120
This utility is useful for representing assignment expressions that will fail at runtime (i.e. when attempting to reassign properties of a [frozen object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)).
121121

122+
此工具对于表示将要在运行时失败的赋值表达式很有用(即,当尝试重新分配 [frozen object] 的属性时(https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze))
123+
122124
##### `Object.freeze`
123125

124126
```ts
@@ -129,12 +131,12 @@ function freeze<Type>(obj: Type): Readonly<Type>;
129131

130132
<blockquote class=bg-reading>
131133

132-
Released:
134+
发布版本:
133135
[2.1](/docs/handbook/release-notes/typescript-2-1.html#partial-readonly-record-and-pick)
134136

135137
</blockquote>
136138

137-
Constructs an object type whose property keys are `Keys` and whose property values are `Type`. This utility can be used to map the properties of a type to another type.
139+
构造一个对象类型,其属性键为“Keys”,其属性值为“Type”。 此工具可用于将一种类型的属性映射到另一种类型。
138140

139141
##### Example
140142

@@ -160,12 +162,12 @@ cats.boris;
160162

161163
<blockquote class=bg-reading>
162164

163-
Released:
165+
发布版本:
164166
[2.1](/docs/handbook/release-notes/typescript-2-1.html#partial-readonly-record-and-pick)
165167

166168
</blockquote>
167169

168-
Constructs a type by picking the set of properties `Keys` (string literal or union of string literals) from `Type`.
170+
通过从 `Type` 中选择一组属性 `Keys`(字符串文字或字符串文字的联合)来构造一个类型。
169171

170172
##### Example
171173

@@ -191,12 +193,12 @@ todo;
191193

192194
<blockquote class=bg-reading>
193195

194-
Released:
196+
发布版本:
195197
[3.5](/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type)
196198

197199
</blockquote>
198200

199-
Constructs a type by picking all properties from `Type` and then removing `Keys` (string literal or union of string literals).
201+
通过从 `Type` 中选择所有属性然后删除 `Keys`(字符串文字或字符串文字的联合)来构造类型。
200202

201203
##### Example
202204

@@ -234,12 +236,12 @@ todoInfo;
234236

235237
<blockquote class=bg-reading>
236238

237-
Released:
239+
发布版本:
238240
[2.8](/docs/handbook/release-notes/typescript-2-8.html#predefined-conditional-types)
239241

240242
</blockquote>
241243

242-
Constructs a type by excluding from `UnionType` all union members that are assignable to `ExcludedMembers`.
244+
通过从“UnionType”中排除所有可分配给“ExcludedMembers”的联合成员来构造一个类型。
243245

244246
##### Example
245247

@@ -256,12 +258,12 @@ type T2 = Exclude<string | number | (() => void), Function>;
256258

257259
<blockquote class=bg-reading>
258260

259-
Released:
261+
发布版本:
260262
[2.8](/docs/handbook/release-notes/typescript-2-8.html#predefined-conditional-types)
261263

262264
</blockquote>
263265

264-
Constructs a type by extracting from `Type` all union members that are assignable to `Union`.
266+
通过从 `Type` 中提取所有可分配给 `Union` 的联合成员来构造一个类型。
265267

266268
##### Example
267269

@@ -276,12 +278,12 @@ type T1 = Extract<string | number | (() => void), Function>;
276278

277279
<blockquote class=bg-reading>
278280

279-
Released:
281+
发布版本:
280282
[2.8](/docs/handbook/release-notes/typescript-2-8.html#predefined-conditional-types)
281283

282284
</blockquote>
283285

284-
Constructs a type by excluding `null` and `undefined` from `Type`.
286+
通过从 `Type` 中排除 `null` `undefined` 来构造一个类型。
285287

286288
##### Example
287289

@@ -296,12 +298,12 @@ type T1 = NonNullable<string[] | null | undefined>;
296298

297299
<blockquote class=bg-reading>
298300

299-
Released:
301+
发布版本:
300302
[3.1](https://github.com/microsoft/TypeScript/pull/26243)
301303

302304
</blockquote>
303305

304-
Constructs a tuple type from the types used in the parameters of a function type `Type`.
306+
从函数类型 `Type` 的参数使用的类型中构造元组类型。
305307

306308
##### Example
307309

@@ -331,12 +333,12 @@ type T7 = Parameters<Function>;
331333

332334
<blockquote class=bg-reading>
333335

334-
Released:
336+
发布版本:
335337
[3.1](https://github.com/microsoft/TypeScript/pull/26243)
336338

337339
</blockquote>
338340

339-
Constructs a tuple or array type from the types of a constructor function type. It produces a tuple type with all the parameter types (or the type `never` if `Type` is not a function).
341+
从构造函数类型的类型构造元组或数组类型。 它生成一个包含所有参数类型的元组类型(如果 `Type` 不是函数,则生成类型 `never`)。
340342

341343
##### Example
342344

@@ -360,12 +362,12 @@ type T4 = ConstructorParameters<Function>;
360362

361363
<blockquote class=bg-reading>
362364

363-
Released:
365+
发布版本:
364366
[2.8](/docs/handbook/release-notes/typescript-2-8.html#predefined-conditional-types)
365367

366368
</blockquote>
367369

368-
Constructs a type consisting of the return type of function `Type`.
370+
构造一个由函数 `Type` 返回的类型组成的类型。
369371

370372
##### Example
371373

@@ -397,12 +399,12 @@ type T8 = ReturnType<Function>;
397399

398400
<blockquote class=bg-reading>
399401

400-
Released:
402+
发布版本:
401403
[2.8](/docs/handbook/release-notes/typescript-2-8.html#predefined-conditional-types)
402404

403405
</blockquote>
404406

405-
Constructs a type consisting of the instance type of a constructor function in `Type`.
407+
构造一个类型,该类型由 `Type` 中的构造函数的实例类型组成。
406408

407409
##### Example
408410

@@ -430,12 +432,12 @@ type T4 = InstanceType<Function>;
430432

431433
<blockquote class=bg-reading>
432434

433-
Released:
435+
发布版本:
434436
[3.3](https://github.com/microsoft/TypeScript/pull/28920)
435437

436438
</blockquote>
437439

438-
Extracts the type of the [this](/docs/handbook/functions.html#this-parameters) parameter for a function type, or [unknown](/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type) if the function type has no `this` parameter.
440+
如果函数类型没有 `this` 参数,则提取函数类型的 [this](/docs/handbook/functions.html#this-parameters) 参数或 [unknown](/docs/handbook/release-notes/typescript-3-0.html# new-unknown-top-type) 类型。
439441

440442
##### Example
441443

@@ -453,12 +455,12 @@ function numberToString(n: ThisParameterType<typeof toHex>) {
453455

454456
<blockquote class=bg-reading>
455457

456-
Released:
458+
发布版本:
457459
[3.3](https://github.com/microsoft/TypeScript/pull/28920)
458460

459461
</blockquote>
460462

461-
Removes the [`this`](/docs/handbook/functions.html#this-parameters) parameter from `Type`. If `Type` has no explicitly declared `this` parameter, the result is simply `Type`. Otherwise, a new function type with no `this` parameter is created from `Type`. Generics are erased and only the last overload signature is propagated into the new function type.
463+
`Type` 中删除 [`this`](/docs/handbook/functions.html#this-parameters) 参数。 如果 `Type` 没有明确声明 `this` 参数,则结果只是 `Type`。 否则,从 `Type` 创建一个没有 `this` 参数的新函数类型。 泛型被删除后,只有最后一个重载签名被传递到新的函数类型中。
462464

463465
##### Example
464466

@@ -476,12 +478,12 @@ console.log(fiveToHex());
476478

477479
<blockquote class=bg-reading>
478480

479-
Released:
481+
发布版本:
480482
[2.3](https://github.com/microsoft/TypeScript/pull/14141)
481483

482484
</blockquote>
483485

484-
This utility does not return a transformed type. Instead, it serves as a marker for a contextual [`this`](/docs/handbook/functions.html#this) type. Note that the [`noImplicitThis`](/tsconfig#noImplicitThis) flag must be enabled to use this utility.
486+
此工具不返回转换后的类型。 相反,它用作上下文 [`this`](/docs/handbook/functions.html#this) 类型的标记。 请注意,必须启用 [`noImplicitThis`](/tsconfig#noImplicitThis) 标志才能使用此工具。
485487

486488
##### Example
487489

@@ -513,9 +515,9 @@ obj.y = 20;
513515
obj.moveBy(5, 5);
514516
```
515517

516-
In the example above, the `methods` object in the argument to `makeObject` has a contextual type that includes `ThisType<D & M>` and therefore the type of [this](/docs/handbook/functions.html#this) in methods within the `methods` object is `{ x: number, y: number } & { moveBy(dx: number, dy: number): number }`. Notice how the type of the `methods` property simultaneously is an inference target and a source for the `this` type in methods.
518+
在上面的例子中,`makeObject` 参数中的 `methods` 对象有一个包含 `ThisType<D & M>` 的上下文类型,因此 [this](/docs/handbook/functions.html#this )`methods` 方法中是 `{ x: number, y: number } & { moveBy(dx: number, dy: number): number }`的联合体。 注意 `methods` 属性的类型是如何成为方法中的 `this` 类型的推理目标和源。
517519

518-
The `ThisType<T>` marker interface is simply an empty interface declared in `lib.d.ts`. Beyond being recognized in the contextual type of an object literal, the interface acts like any empty interface.
520+
`ThisType<T>` 标记接口只是在`lib.d.ts` 中声明的一个空接口。 除了在对象字面量的上下文类型中被识别之外,接口的行为就像任何空接口。
519521

520522
## Intrinsic String Manipulation Types
521523

@@ -527,4 +529,4 @@ The `ThisType<T>` marker interface is simply an empty interface declared in `lib
527529

528530
### `Uncapitalize<StringType>`
529531

530-
To help with string manipulation around template string literals, TypeScript includes a set of types which can be used in string manipulation within the type system. You can find those in the [Template Literal Types](/docs/handbook/2/template-literal-types.html#uppercasestringtype) documentation.
532+
TypeScript 包含一组可用于系统内的字符串类型操作的类型,以便于使用模板字符串进行操作。 您可以在 [Template Literal Types](/docs/handbook/2/template-literal-types.html#uppercasestringtype) 文档中找到这些内容。

0 commit comments

Comments
 (0)