Partial<Type>

Constructs a type with all properties of Type set to optional. This utility will return a type that represents all subsets of a given type.

Example

Implementation

More Implementation: PartialExclude<Type, Keys>

Constructs a type with all properties of Type set to optional except specific Keys.

More Implementation: PartialWith<Type, Keys>

Constructs a type will all properties of Type and set specific Keys to optional.

Readonly<Type>

Constructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be reassigned.

Example

Implementation

More Implementation: Unreadonly<Type>

Constructs a type with all properties of Type remove readonly modifier, meaning the properties of the constructed type are allowed to be reassigned.

Record<Keys, Type>

Constructs a type with a set of properties Keys of type Type. This utility can be used to map the properties of a type to another type.

Example

Implementation

More Implementation: MergeRecord<Record, Record>

Pick<Type, Keys>

Constructs a type by picking the set of properties Keys from Type.

Example

Implementation

More Implementation: PickWithTypes<Types, Subtypes>

Constructs a type by picking properties which type in the set of Subtypes from Type.

Omit<Type, Keys>

Constructs a type by picking all properties from Type and then removing Keys.

Example

Implementation

More Implementation: OmitOptional<Type>

Construct a type by omitting all optional properties.

Exclude<Type, ExcludedUnion>

Constructs a type by excluding from Type all union members that are assignable to ExcludedUnion.

Example

Implementation

More Implementation: ExcludeKeysInType<Type, Record>

Extract<Type, Union>

Constructs a type bu extracting from Type all union members that are assignable to Union.

Example

Implementation

NonNullable<Type>

Constructs a type by excluding null and undefined from Type.

Example

Implementation

Parameters<Type>

Constructs a tuple type from the types used in the parameters of a function type Type.

Example

Implementation

ConstructorParameters<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).

Example

Implementation

ReturnType<Type>

Constructs a type consisting of the return type of function Type.

Example

Implementation

InstanceType<Type>

Constructs a type consisting of the instance type of a constructor function in Type.

Example

Implementation

Required<Type>

Constructs a type consisting of all properties of T set to required. The opposite of Partial.

Example

Implementation

More Implementation: RequiredProps<Type, RequiredUnion>

ThisParameterType<Type>

Extracts the type of the this parameter for a function type, or unknown if the function type has no this parameter.

Example

Implementation

OmitThisParameter<Type>

Removes the this parameter from Type. if Type has no explicity 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.

Example

Implementation

ThisType<Type>

This utility does not return a transformed type. Instead, it serves as a marker for a contextual this type. Note that the --noImplicitThis flag must be enabled to use this utility.

Example

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 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 interface 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.
💡
If you add & ThisType<WhateverYouWantThisToBe> to the type fo an object, the functions within that object will have WhateverYouWantThisToBe as the type used for this. This is helpful if you can't otherwise specify what this should be through the normal TypeScript mechanisms.

Implementation

 
badge