`keyof T` produces a union of a type's property names as string literal types. Indexed access `T[K]` looks up the type of a specific property.
ts
interface Token { symbol: string; decimals: number; }
type TokenKey = keyof Token; // "symbol" | "decimals"
function getProp<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
const t: Token = { symbol: "ETH", decimals: 18 };
const d = getProp(t, "decimals"); // numberThis pattern gives fully type-safe generic property access — `getProp(t, "decimals")` returns `number`, and passing a key that doesn't exist on `Token` is a compile error, unlike an unchecked `obj[key]` with `key: string`.