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
This type is intended to be simulated async function await or something like thatPromise on.then() Methods - Specifically, they are recursive
unfoldPromise
Construct a will Type All properties are set to readonlyof the constructed type, which means that these properties cannot be reassigned to the constructed type.
This utility is useful for representing assignment expressions that will fail at runtime (i.e. when attempting to reassign properties of a frozen object).
Constructs a tuple or array type from the type of the constructor type. It generates a tuple type that contains all parameter types (if so Type If it is not a function, the type is generated never)。
If the function type is not this parameters, then extract the function type this Parameter or [unknown](/docs/handbook/release-notes/typescript-3-0.html# new-unknown-top-type) type.
from Type delete this Parameter. If Type There is no explicit statement this parameters, then the result is only Type。 Otherwise, from Type Create one that does not this The new function type of the parameter. After the generic is removed, only the last overloaded signature is passed to the new function type.
This tool does not return the converted type. Instead, it is used as a context this The type of tag. Note that it must be enabled noImplicitThis flags are required to use this tool.
Example
// @noImplicitThis: falsetypeObjectDescriptor<D,M>={data?: D;methods?: M&ThisType<D&M>;// Type of 'this' in methods is D & M};functionmakeObject<D,M>(desc: ObjectDescriptor<D,M>): D&M{letdata: object=desc.data||{};letmethods: object=desc.methods||{};return{ ...data, ...methods}asD&M;}letobj=makeObject({data: {x: 0,y: 0},methods: {moveBy(dx: number,dy: number){this.x+=dx;// Strongly typed thisthis.y+=dy;// Strongly typed this},},});obj.x=10;obj.y=20;obj.moveBy(5,5);
In the example above,makeObject parameter methods The object has a containment ThisType<D & M> The context type, therefore this at methods Method is { x: number, y: number } & { moveBy(dx: number, dy: number): number }consortium. note methods How the type of the property becomes in a method this The type of inference target and source.
ThisType<T> Tag the interface just inlib.d.ts An empty interface declared in . Except for being recognized in the context type of the object literal, the interface behaves like any empty interface.
Intrinsic String Manipulation Types
Uppercase<StringType>
Lowercase<StringType>
Capitalize<StringType>
Uncapitalize<StringType>
TypeScript contains a set of types that can be used for string-type operations within the system to facilitate operations using template strings. You can Template Literal Types Find these in the documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
translate Utility Types to chinese