CodeDiscriminated union
type Result<T> =
| { status: "success"; data: T }
| { status: "error"; message: string };
function render(result: Result<string>) {
return result.status === "success" ? result.data : result.message;
}Use this TypeScript cheatsheet for high-frequency syntax and type-system patterns without turning everyday code into unnecessary abstractions.
const count: number = 3const ids: string[] = []type Point = [number, number]readonly string[]type User = { id: string; name: string }interface User { id: string; name: string }avatarUrl?: stringRecord<string, number>type State = 'idle' | 'loading' | 'error'type Admin = User & Permissionskeyof UserUser['id']if (typeof value === 'string')if ('error' in result)function isUser(value: unknown): value is Userconst unreachable: never = statefunction first<T>(items: T[]): T | undefinedPartial<User>Pick<User, 'id' | 'name'>Omit<User, 'password'>ReturnType<typeof buildUser>(value: string) => voidvalue: unknownNarrow before use.
value: anyDisables checking; keep escape hatches isolated.
Promise<User>type Result<T> =
| { status: "success"; data: T }
| { status: "error"; message: string };
function render(result: Result<string>) {
return result.status === "success" ? result.data : result.message;
}type ButtonProps = {
children: React.ReactNode;
onClick: () => void;
disabled?: boolean;
};TypeScript Cheatsheet includes quick reference sections, practical examples, common mistakes, tips and links to related DevKitYard tools.
This cheatsheet is a static quick reference focused on concise commands, syntax and examples.
Use it when you need to recall syntax, compare common patterns or avoid mistakes without opening a long tutorial.
Use related DevKitYard tools such as JSON Formatter when you need to format, validate, generate or inspect real output.