TypeScript Utility Types

I want to read more about TypeScript Utility types. (https://www.typescriptlang.org/docs/handbook/utility-types.html)

Date Created:
1 70

References



Notes


TypeScript offers a variety of utility types to facilitate common type transformations. Here's a summary of some of the key utility types:

  • Partial<Type>: Constructs a type with all properties of Type set to optional, representing all subsets of a given type.
  • Required<Type>: Constructs a type with all properties of Type set to required, the opposite of Partial.
  • Readonly<Type>: Constructs a type with all properties of Type set to readonly, preventing modification of the properties.
  • Record<Keys, Type>: Constructs a type with a set of properties Keys of type Type.
  • Pick<Type, Keys>: Constructs a type by picking a set of properties Keys from Type.
  • Omit<Type, Keys>: Constructs a type by omitting a set of properties Keys from Type.
  • Exclude<UnionType, ExcludedMembers>: Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers.
  • Extract<UnionType, ExtractedMembers>: Constructs a type by extracting from UnionType all union members that are assignable to ExtractedMembers.
  • NonNullable<Type>: Constructs a type by excluding null and undefined from Type.
  • Parameters<Type>: Constructs a tuple type from the types used in the parameters of a function type Type.
  • ConstructorParameters<Type>: Constructs a tuple or array type from the types used in the parameters of a constructor function type Type.
  • ReturnType<Type>: Constructs a type consisting of the return type of function Type.
  • InstanceType<Type>: Constructs a type consisting of the instance type of a constructor function type Type.
  • ThisParameterType<Type>: Extracts the type of the this parameter for a function type, or unknown if the function type has no this parameter.
  • OmitThisParameter<Type>: Removes the this parameter from Type.
  • ThisType<Type>: Used to specify the type of this in methods of an object.
  • Awaited<Type>: Used to model operations like await in async functions, recursively unwrapping Promises.

You can read more about how comments are sorted in this blog post.

User Comments

Frank
Frank 3d ago

This is the only content on this site so far that was generated by an AI. It was late one night and I wanted to try to keep the daily reading streak alive, so I had this generated (and changed some formatting). I need to learn how to manage TypeScript types better.

0 1 7

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Files

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language

Upload Previous Version of Editor State

ESC