Skip to main content

TypeScript Reference

v1.0.0

Searchable reference for TypeScript types, utility types, generics, and type constructs.

36 entries found

stringPrimitive Types

string

Represents text values.

let name: string = 'Alice';
numberPrimitive Types

number

Represents both integer and floating-point numbers.

let age: number = 30;
booleanPrimitive Types

boolean

Represents true or false values.

let active: boolean = true;
bigintPrimitive Types

bigint

Arbitrary-precision integer.

let big: bigint = 9007199254740993n;
symbolPrimitive Types

symbol

Unique and immutable primitive.

const id: symbol = Symbol('id');
nullPrimitive Types

null

Represents deliberate absence of value.

let val: string | null = null;
undefinedPrimitive Types

undefined

Variable declared but not assigned.

let x: number | undefined;
anyPrimitive Types

any

Disables type checking for a value — use sparingly.

let raw: any = JSON.parse(data);
unknownPrimitive Types

unknown

Like any but type-safe — must narrow before use.

if (typeof val === 'string') { ... }
neverPrimitive Types

never

Represents values that never occur — unreachable code.

function fail(msg: string): never { throw new Error(msg); }
voidPrimitive Types

void

Absence of a return value.

function log(msg: string): void { console.log(msg); }
Partial<T>Utility Types

Partial<T>

Makes all properties in T optional.

type PartialUser = Partial<User>;
Required<T>Utility Types

Required<T>

Makes all properties in T required.

type RequiredConfig = Required<Config>;
Readonly<T>Utility Types

Readonly<T>

Makes all properties in T readonly.

const config: Readonly<Config> = { ... };
Record<K, V>Utility Types

Record<K, V>

Constructs a type with keys K and values V.

type Dict = Record<string, number>;
Pick<T, K>Utility Types

Pick<T, K>

Constructs a type with only properties K from T.

type Preview = Pick<User, 'name' | 'avatar'>;
Omit<T, K>Utility Types

Omit<T, K>

Constructs a type by removing properties K from T.

type NoId = Omit<User, 'id'>;
Exclude<T, U>Utility Types

Exclude<T, U>

Excludes types assignable to U from T.

type NonNull = Exclude<string | null, null>;
Extract<T, U>Utility Types

Extract<T, U>

Extracts types assignable to U from T.

type Strings = Extract<string | number, string>;
NonNullable<T>Utility Types

NonNullable<T>

Excludes null and undefined from T.

type Safe = NonNullable<string | null>;
ReturnType<T>Utility Types

ReturnType<T>

Obtains the return type of a function type.

type R = ReturnType<typeof getUser>;
Parameters<T>Utility Types

Parameters<T>

Obtains the parameter types of a function as a tuple.

type P = Parameters<typeof fetch>;
Awaited<T>Utility Types

Awaited<T>

Recursively unwraps a Promise type.

type User = Awaited<ReturnType<typeof fetchUser>>;
UnionType Constructs

A | B

Value can be one of multiple types.

type Id = string | number;
IntersectionType Constructs

A & B

Value must satisfy all types simultaneously.

type Admin = User & { role: 'admin' };
TupleType Constructs

[A, B, C]

Fixed-length array with known types per position.

const pair: [string, number] = ['age', 30];
Conditional TypeType Constructs

T extends U ? X : Y

Selects a type based on a condition.

type IsString<T> = T extends string ? true : false;
Mapped TypeType Constructs

{ [K in keyof T]: ... }

Iterates over keys of type T to transform it.

type Optional<T> = { [K in keyof T]?: T[K] };
Template LiteralType Constructs

`${A}${B}`

Constructs string literal types from template expressions.

type EventName = `on${Capitalize<string>}`;
inferType Constructs

infer R

Infers a type variable within a conditional type.

type UnpackPromise<T> = T extends Promise<infer U> ? U : T;
keyofType Constructs

keyof T

Produces a union of all property key types of T.

type Keys = keyof User; // 'id' | 'name' | ...
typeofType Constructs

typeof value

Obtains the type of a variable or expression.

type Config = typeof defaultConfig;
as constType Constructs

value as const

Widens literal types to their narrowest form.

const roles = ['admin', 'user'] as const;
Generic FunctionGenerics

function fn<T>(arg: T): T

A function parameterised over a type.

function identity<T>(arg: T): T { return arg; }
Generic ConstraintGenerics

<T extends U>

Constrains T to types assignable to U.

function getLength<T extends { length: number }>(v: T): number { return v.length; }
Default Type ParamGenerics

<T = Default>

Provides a default type if T is not inferred.

interface Box<T = string> { value: T; }