Type alias Flip<T>

Flip<T>: {
    [P in Keys<T> as StringifyPrimitive<T[P]>]: P
}

Constructs a new type that takes an object type T and returns a new object type where the keys of T become the values and the values become the keys.

Type Parameters

  • T extends _FlippableRecord

Example

type Object1 = { name: 'John'; age: 30; city: 'New York' };
type Flipped1 = Flip<Object1>; // {'John': 'name', 30: 'age', 'New York': 'city'}

type Object2 = { fruit: 'Apple'; color: 'Red'; price: 1.25 };
type Flipped2 = Flip<Object2>; // {'Apple': 'fruit', 'Red': 'color', 1.25: 'price'}

type Object3 = { optionA: true; optionB: false };
type Flipped3 = Flip<Object3>; // {true: 'optionA', false: 'optionB'}