I am trying to declare an object which should have all keys of MyEnum
with the value of type EnumValue
and any other keys with string
type value. Please see the example below.
enum MyEnum {
A = 'A',
B = 'B',
}
type EnumValue = {
title: string;
infoText: string;
};
type RequiredType = Record<MyEnum, EnumValue>;
const myObj = {
A: { infoText: 'a', title: 'a title' },
B: { infoText: 'b', title: 'b title' },
someOtherKey: 'string value',
};
How to specify the type for myObj
so it would be of type Record<MyEnum, EnumValue>
as the required type (all enum values should be included as keys) and additionally accept Record<string, string>
type?
Edit: also I would like to have autocompletion for all keys in that object. Is it possible by inferring properties from declared myObj
?