Built-in Utility Types
When a particular type feels like it's useful in most
codebases, they are added into TypeScript and become
available for anyone which means you can consistently
rely on their availability
Partial
// Creates a type which uses the list of properties from
KeysFrom and gives them the value of Type.
List which keys come from:
interface Sticker {
id: number;
name: string;
createdAt: string;
updatedAt: string;
submitter: undefined | string;
}
type StickerUpdateParam = Partial
// Creates a type by picking the set of properties Keys
from Type. Essentially an allow-list for extracting type
information from a type.
type NavigationPages = "home" | "stickers" | "about" | "contact";
// The shape of the data for which each of ^ is needed:
interface PageInfo {
title: string;
url: string;
axTitle?: string;
}
const navigationInfo: Record
// Creates a type by removing the set of properties Keys
from Type. Essentially a block-list for extracting type
information from a type.
type StickerSortPreview = Pick
// Creates a type where any property in Type's properties
which don't overlap with RemoveUnion.
type StickerTimeMetadata = Omit
// Creates a type where any property in Type's properties
are included if they overlap with MatchUnion.
type HomeNavigationPages = Exclude
// Creates a type by excluding null and undefined from a set
of properties. Useful when you have a validation check.
type DynamicPages = Extract
// Creates a type which is an instance of a class, or object
with a constructor function.
type StickerLookupResult = Sticker | undefined | null;
type ValidatedResult = NonNullable
// Creates a type which converts all optional properties
to required ones.
class StickerCollection {
stickers: Sticker[];
}
type CollectionItem = InstanceType
// Unlike other types, ThisType does not return a new
type but instead manipulates the definition of this
inside a function. You can only use ThisType when you
have noImplicitThis turned on in your TSConfig.
https://www.typescriptlang.org/docs/handbook/utility-types.html
type AccessiblePageInfo = Required