'Wrap 'K in keyof T' with a generic type

 type CustomFieldWrapper<T> = {
  isDirty: boolean
  value: T
}

type WrappedFormValues<T>> = {
    CustomFieldWrapper< [K in keyof T]: T[K] >
};

I would like to make sure that all [K in keyof T]: T[K], are also wrapped with my CustomFieldWrapper

Then I want to be able to

var myfield: WrappedFormValues<{ name: string, email: string}> = {
         name: GetCustomFieldWrapper("name", "initial name value"),
         email: GetCustomFieldWrapper("email", "initial email value"),
}

Now obviously I cannot use that syntax. CustomFieldWrapper < something > doesnt work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source