This document explains the fundamental building blocks used throughout the toolkit. These utilities help write cleaner, safer TypeScript code.
What it does:
Represents a class blueprint. Useful when working with classes directly.
Example:
class Car {}
const createVehicle = (ctor: Constructor<Car>) => new ctor();
createVehicle(Car); // Works!What it does:
"Maybe there's a value, maybe not." Represents optional values.
Example:
let username: Maybe<string>; // Can be string, null, or undefined
username = 'John';
username = null; // Also OKWhat it does:
A fancy name for simple key-value objects.
Example:
const prices: Dictionary<number> = {
apple: 1.99,
banana: 0.99,
};What it does:
For when you need to work with both regular numbers and big numbers.
Example:
function add(a: Numeric, b: Numeric): Numeric {
return a + b; // Works with 5 or 9007199254740991n
}What they do:
Primitive: Basic value types (string, number, etc.)PrimitiveObject: Their object versions (String, Number, etc.)
Example:
function logValue(val: Primitive) {
console.log(val); // Accepts "hello", 42, true, etc.
}What they do:
Noop: Empty function placeholderCallback: Flexible function with arguments
Example:
const emptyFunction: Noop = () => {};
const buttonClick: Callback<[MouseEvent]> = (event) => {...};What it does:
Makes all properties in an object optional (can be null).
Example:
type User = { name: string; age: number };
type SafeUser = Nullable<User>; // { name: string|null; age: number|null }What they do:
NonNull<T>: No nulls allowedNonUndefined<T>: No undefinedNonNullable<T>: No null/undefined
Example:
function requireValue(val: NonNull<string>) {
// val can't be null here
}What it does:
Named constants for HTTP status codes. No more remembering numbers!
Common uses:
res.status(HttpStatus.NOT_FOUND); // Instead of 404
if (errorCode === HttpStatus.UNAUTHORIZED) { ... }Full list includes:
HttpStatus.OK; // 200
HttpStatus.NOT_FOUND; // 404
HttpStatus.I_AM_A_TEAPOT; // 418 🫖
HttpStatus.INTERNAL_SERVER_ERROR; // 500