Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.
Scope and conventions
TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.
number is always an IEEE 754 double, so integers are doubles too (bigint holds arbitrary-size integers). string and boolean are primitive types. Type aliases/interfaces describe shapes; they do not construct runtime objects.
Fragment
Complete custom type and values.
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
type Point = { x: number; y: number;};const point: Point = { x: 2, y: 5 };const labels: string[] = ["north", "west"];
: annotates a type; . accesses a member. [] indexes or destructures. Backticks interpolate ${…}; \n, \r and \t escape LF, CR and tab. Single/double quotes both create strings.
Fragment
Fragment inside a function or module.
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const [first, second] = [2, 5];const label = `item ${first}`;const next = (n: number) => n + second;
With strictNullChecks, null and undefined must be allowed by the type. A ? property may be absent. ?. stops on null/undefined; ?? supplies a fallback for those two values, preserving false, 0 and empty text.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
type aliases and interfaces describe object shapes. readonly restricts writes through that type; it does not deeply freeze the object at runtime. An object literal supplies the actual value.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
interface Point { readonly x: number; y: number;}const point: Point = { x: 2, y: 5 };point.y = 8;
A tuple type records element positions and types. Destructuring binds positions to names. as const can infer a readonly literal tuple instead of a general mutable array.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
A literal union restricts allowed values. A discriminated union can associate different fields with each tag; checking the tag narrows the shape. A type alias is erased at runtime.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
A generic parameter preserves a relationship between input and output types. Type arguments can often be inferred. An extends constraint limits which types are accepted; it is not runtime validation.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
function identity<T>(value: T): T { return value;}const count = identity<number>(24);const name = identity("north");
Interfaces are structural: a value fits if it has the required members. implements checks a class declaration but does not create runtime dispatch or change method bodies.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
interface Named { name(): string;}const item: Named = { name() { return "north"; }};
unknown requires narrowing before use; any disables many checks. typeof/instanceof/in are runtime checks that can narrow. as asserts a type to the checker; it does not validate or convert the runtime value.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
An intersection A & B requires both contracts. keyof obtains property keys; type-position typeof obtains the type of a value; T[K] selects a property’s type. These describe types, not runtime validation.
Fragment
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
type Named = { name: string };type Counted = { count: number };type Item = Named & Counted;type Keys = keyof Item;type Name = Item["name"];const defaults = { retries: 3 };type Defaults = typeof defaults;
Mapped types iterate keys to build another type. Partial, Pick, Omit, Record and ReturnType are compile-time utilities; none copies or validates runtime values.
as const narrows literals and adds readonly type information. satisfies checks compatibility while retaining the expression’s useful inferred type. Neither freezes an object or validates outside data at runtime.
Fragment
main.ts
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
type Options = { mode: "fast" | "safe"; retries: number };const options = { mode: "safe", retries: 3} as const satisfies Options;