Type queries mirror runtime values in the type system. • typeof: capture the type of a value • keyof: union of property names • indexed access: T[K] to grab a property type These enable DRY typing that follows the runtime objects you already have. **Why it matters:** • Prevents drift between runtime objects and types—one source of truth • Great for event maps, route configs, and API response shapes • Reduces duplication and keeps refactors safe
const user = { id: 1, name: "Ada" } as const;
type User = typeof user;const user = { id: 1, name: "Ada", active: true } as const;
type User = typeof user;
type UserKeys = keyof User; // "id" | "name" | "active"
type NameType = User["name"]; // "Ada"
// Generic helper using indexed access
type ValueOf<T> = T[keyof T];
type Primitive = ValueOf<{ a: string; b: number }>; // string | number
// keyof with Record
type ApiResponse<T> = { data: T; status: number };
type ResponseStatus = ApiResponse<string>["status"];Understanding typeof, keyof, Indexed Access is fundamental to mastering TypeScript. Practice with the examples above and experiment with variations to solidify your knowledge.