TypeScript Reference
v1.0.0Searchable reference for TypeScript types, utility types, generics, and type constructs.
36 entries found
string
Represents text values.
let name: string = 'Alice';
number
Represents both integer and floating-point numbers.
let age: number = 30;
boolean
Represents true or false values.
let active: boolean = true;
bigint
Arbitrary-precision integer.
let big: bigint = 9007199254740993n;
symbol
Unique and immutable primitive.
const id: symbol = Symbol('id');null
Represents deliberate absence of value.
let val: string | null = null;
undefined
Variable declared but not assigned.
let x: number | undefined;
any
Disables type checking for a value — use sparingly.
let raw: any = JSON.parse(data);
unknown
Like any but type-safe — must narrow before use.
if (typeof val === 'string') { ... }never
Represents values that never occur — unreachable code.
function fail(msg: string): never { throw new Error(msg); }void
Absence of a return value.
function log(msg: string): void { console.log(msg); }Partial<T>
Makes all properties in T optional.
type PartialUser = Partial<User>;
Required<T>
Makes all properties in T required.
type RequiredConfig = Required<Config>;
Readonly<T>
Makes all properties in T readonly.
const config: Readonly<Config> = { ... };Record<K, V>
Constructs a type with keys K and values V.
type Dict = Record<string, number>;
Pick<T, K>
Constructs a type with only properties K from T.
type Preview = Pick<User, 'name' | 'avatar'>;
Omit<T, K>
Constructs a type by removing properties K from T.
type NoId = Omit<User, 'id'>;
Exclude<T, U>
Excludes types assignable to U from T.
type NonNull = Exclude<string | null, null>;
Extract<T, U>
Extracts types assignable to U from T.
type Strings = Extract<string | number, string>;
NonNullable<T>
Excludes null and undefined from T.
type Safe = NonNullable<string | null>;
ReturnType<T>
Obtains the return type of a function type.
type R = ReturnType<typeof getUser>;
Parameters<T>
Obtains the parameter types of a function as a tuple.
type P = Parameters<typeof fetch>;
Awaited<T>
Recursively unwraps a Promise type.
type User = Awaited<ReturnType<typeof fetchUser>>;
A | B
Value can be one of multiple types.
type Id = string | number;
A & B
Value must satisfy all types simultaneously.
type Admin = User & { role: 'admin' };[A, B, C]
Fixed-length array with known types per position.
const pair: [string, number] = ['age', 30];
T extends U ? X : Y
Selects a type based on a condition.
type IsString<T> = T extends string ? true : false;
{ [K in keyof T]: ... }
Iterates over keys of type T to transform it.
type Optional<T> = { [K in keyof T]?: T[K] };`${A}${B}`
Constructs string literal types from template expressions.
type EventName = `on${Capitalize<string>}`;infer R
Infers a type variable within a conditional type.
type UnpackPromise<T> = T extends Promise<infer U> ? U : T;
keyof T
Produces a union of all property key types of T.
type Keys = keyof User; // 'id' | 'name' | ...
typeof value
Obtains the type of a variable or expression.
type Config = typeof defaultConfig;
value as const
Widens literal types to their narrowest form.
const roles = ['admin', 'user'] as const;
function fn<T>(arg: T): T
A function parameterised over a type.
function identity<T>(arg: T): T { return arg; }<T extends U>
Constrains T to types assignable to U.
function getLength<T extends { length: number }>(v: T): number { return v.length; }<T = Default>
Provides a default type if T is not inferred.
interface Box<T = string> { value: T; }