Suppose I have the following:
const myObj = { foo: 'cat', bar: 'dog', baz: 'bird' } as const;
type MyValue = 'fish' | 'bear' | 'cow';
const myValueMap: Record<string, MyValue> = {
[myObj.foo]: 'fish',
[myObj.bar]: 'cow',
} as const;
Because myValueMap is declared as an object with arbitrary string keys, we don't get type-checking on the actual keys of the object (cat and dog). I could remove the explicit declaration altogether, but then I don't enforce that the values are MyValues. (In my actual code, MyValue is several hundred constants strings.)
Is there a way, preferably without using a wrapper function, to enforce that values are MyValues and still maintain the property type-checking?