Is there a way to set the values of this object as const
, while ensuring that the keys are limited to the Field
union?
type Field = 'name' | 'isHappy';
const fieldTypes: { [field in Field]: string } = {
name: 'text',
isHappy: 'checkbox',
};
I want the type of fieldTypes
to be:
{
name: 'text';
isHappy: 'checkbox';
}
instead of
{
name: string;
isHappy: string;
}