type KeyFromValue < V , T extends Record < PropertyKey , PropertyKey > > = { [ K in keyof T ] : V extends T [ K ] ? K : never ; } [ keyof T ] ; type Invert < T extends Record < PropertyKey , PropertyKey > > = { [ V in T [ keyof T ] ] : KeyFromValue < V , T > ; } ; export function invert < T extends Record < PropertyKey , PropertyKey > > ( obj ) { const newObj = Object . create ( null ) as any ; for ( const key in obj ) { const v = obj [ key ] ; newObj [ v ] = key ; } return newObj ; }