Three type-level operators that compose:
keyof Tproduces a union of the keys ofTas literal types:keyof { x: number; y: number }is"x" | "y". With an index signature it gives the index type:keyof { [k: string]: boolean }isstring | number(JS coerces numeric keys to strings), andkeyof { [n: number]: unknown }isnumber.typeof xin a type position takes a value (a variable, property or class) and gives its static type. It is separate from the runtimetypeofthat returns a string. It accepts only identifiers and their properties, not calls:typeof f()is a syntax error, so you writeReturnType<typeof f>.T[K]is an indexed access type: the type of propertyKinT.Kcan be a union (Config["host" | "port"]isstring | number),keyof T(all values), ornumberfor arrays and tuples (Item[number]is the element type). A key that does not exist is an error (TS2339), and so is a value used as the key.
They are for deriving types from one source of truth. The classic is an as const array: (typeof roles)[number] is the union of its elements, so adding a role updates both the runtime list and the type. Also Obj[keyof Obj] for "any value" and K extends keyof T to constrain a key parameter (see the generics question).
Remember the namespaces: typeof bridges value to type; nothing here runs at runtime, and a const key = "port" cannot be used as an index type without typeof key.