Types from both keys and values of object in Typescript

PHOTO EMBED

Tue Feb 08 2022 13:19:24 GMT+0000 (Coordinated Universal Time)

Saved by @avivdaniel #javascript

const KeyToVal = {
    MyKey1: 'myValue1',
    MyKey2: 'myValue2',
} as const;

type Keys = keyof typeof KeyToVal;
type Values = typeof KeyToVal[Keys]; //  "myValue1" | "myValue2"
content_copyCOPY

https://stackoverflow.com/questions/53662208/types-from-both-keys-and-values-of-object-in-typescript