You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/documentation/zh/reference/Utility Types.md
+32-30Lines changed: 32 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: 多功能类型
2
+
title: 工具类型
3
3
layout: docs
4
4
permalink: /zh/docs/handbook/utility-types.html
5
5
oneline: TypeScript 中全局包含的类型
@@ -119,6 +119,8 @@ todo.title = "Hello";
119
119
120
120
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)).
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.
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).
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.
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.
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.
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.
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.
@@ -527,4 +529,4 @@ The `ThisType<T>` marker interface is simply an empty interface declared in `lib
527
529
528
530
### `Uncapitalize<StringType>`
529
531
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.
0 commit comments