Пример
Getter, provably safe против опечаток:
function pluck<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
const user = { id: 1, name: 'Ada' };
pluck(user, 'name');
const STATUS = { active: 1, archived: 2 } as const;
type StatusKey = keyof typeof STATUS;
type StatusCode = typeof STATUS[StatusKey];
type Dict = { [k: string]: number };
type DictKeys = keyof Dict;
Итог
pluck — классика K extends keyof T; const object + keyof typeof держит keys и codes синхронными.