TypeScript Types
TypeScript Types
Cheat Sheet Type Key points Full name is “type alias” and are used
to provide names to type literals
Supports more rich type-system
features than interfaces.
These features are great for building libraries, describing existing
JavaScript code and you may find you rarely reach for them in
mostly TypeScript applications.
^ s
interface comparison checks /** In bytes */
// Attached docs
Loop through each field
Sets type as a function with
can be faster. payloadSize: number;
//
in the type generic type Subscriber<Type> = {
original type as param
outOfStock?: boolean;
// Optional
parameter “Type”
[Property in keyof Type]:
similar semantics.
new (s: string): JSONResponse;
// Newable
// bio: (nv: string) => void }
Build with Utility Types readonly body: string;
// Readonly property
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 thetypeof operator.
type SanitizedInput = string;
type Size =
const data = { ... }
type Animals = Bird | Dog | Ant | Wolf;
x: number;
A way to merge/extend types Re-use the return value from a
Template Union Types
y: number;
type Location =
// { x: number, y: number }
Tuple Type ReturnType<typeof createFixtures>
type AllLocaleIDs =
type Data = [
a subset of a type. Type from Module `${SupportedLangs}_${FooterLocaleIDs}_id`;
// "en_header_id" | "en_footer_id"
location: Location,
type Response = { data: { ... } }
| "pt_header_id" | "pt_footer_id"
// { ... }