TypeScript Types
TypeScript Types
Type
Full name is “type alias” and are used Supports more rich type-system These features are great for building libraries, describing existing
Key points
Cheat Sheet to provide names to type literals features than interfaces. JavaScript code and you may find you rarely reach for them in
mostly TypeScript applications.
similar semantics.
new (s: string): JSONResponse;
// Newable
// bio: (nv: string) => void }
Build with Utility Types readonly body: string;
// Readonly property
} Conditional Types
TypeScript includes a lot of
global types which will help you Terser for saving space, see Interface Cheat Sheet for
do common tasks in the type more info, everything but ‘static’ matches. Acts as “if statements” inside the type system. Created
system. Check the site for them. via generics, and then commonly used to reduce the
number of options in a type union.
Useful for documentation mainly Describes a type which is one of many options, Re-use the type from an existing JavaScript : never
for example a list of known strings. runtime value via the typeof operator.
type SanitizedInput = string;
"small" | "medium" | "large" type Data = typeof data type FourLegs = HasFourLegs<Animals>
// { x: number, y: number }
type Fixtures =
type SupportedLangs = "en" | "pt" | "zh";
ReturnType<typeof createFixtures>
Tuple Type
Type Indexing
type Data = [
a subset of a type. Type from Module // "en_header_id" | "en_footer_id"
location: Location,
type Response = { data: { ... } }
| "pt_header_id" | "pt_footer_id"
// { ... }