title: How to get the all types of all the props of interface into one type variable in TypeScript
body: <p>I am building a web application with Typescript. In my code, I got into a situation where I need to get all the types of every prop of an object/interface into a type variable.</p>
  <p>I have an interface with the following code:</p>
  <pre><code>interface ProductForm {
      name: string;
      id: number | string;
      categoryId: number;
      status: ProductStatus // enum
  }
  </code></pre>
  <p>As you can see, the above interface has 4 props and they have different types.</p>
  <p>I want to have a function as follows:</p>
  <pre><code>const updateProductFormField = (name: keyof ProductForm, value: any) =&gt; {
     // update the field
  }
  </code></pre>
  <p>As you can see in the above code, the function first parameter, <code>name</code> must be one of the props of the <code>ProductForm</code> interface. The second argument has type, <code>any</code> which I am trying to get rid of. The value must be one of the type of types of the props of ProductForm interface.</p>
  <p>Basically I am trying to get all types of props of ProductForm into one variable like this:</p>
  <pre><code>type FormValueTypes = ProductForm['name'] | ProductForm['id'] | ProductForm['categoryId'] | ProductForm['status'];
  </code></pre>
  <p>Then use that type for second argument. But I am hardcoding in the fields in the code above? When a new field is added to the interface, I will have to change that variable too. Is that a more dynamic to achieve the same thing?</p>