title: access/set object's values by indexing it by property name
body: <p>I have an object called caser and it has the following properties:</p>
  <pre><code>export interface ICaser {
      consulter: string;
      associater: string;
      typologies: string[];
      id:number;
  }
  
  const caser: ICaser = {
      consulter: &quot;john&quot;,
      associater: &quot;Huns&quot;,
      typologies: ['starter', 'beginner','intermediary','advanced']
  };
  </code></pre>
  <p>And I am accessing the property by indexing, as follows:</p>
  <pre><code>_caser[fieldName as keyof ICaser] = value.key as string;
  </code></pre>
  <p>However, this works only for properties which are string type and not for property 'typologies' which is an array of strings.</p>
  <p>My question is, how can I make it more generic that it can take any property, whether it is of type string, integer or array?</p>
  <pre><code>const handleOnFieldChange = (fieldName: string, value: IDropdownOption, index?: number | undefined) =&gt; {
  
          let _caser = Object.assign({}, caser);
          var vls;
          if (fieldName === &quot;typologies&quot;) {
              vls = value.selected ?
                  [..._caser.typologies!, value.key as string] : _caser.typologies.filter(key =&gt; key !== value?.key);
              _caser['typologies'] = vls;
  
          } else {
              _caser[fieldName as keyof ICaser] = value.key as string;
          }
          setCaser(_caser);
      }
  </code></pre>
  <p>using the example above, I will get the following which of course makes sense, but how do I solve it?</p>
  <pre><code>ype 'string' is not assignable to type 'string &amp; string[]'.
    Type 'string' is not assignable to type 'string[]'.
  </code></pre>
  <p>Edit:
  using it as follows: <code>_caser[fieldName]</code>, gives the following error:</p>
  <pre><code>Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ICaser'.
  </code></pre>