title: How to change type of properties via key match in TypeScript
body: <p>I have an object that is already dynamically typed. Those types are mostly correct except one thing which is not picked up by TypeScript itself.</p>
  <p>I iterate over the object and I convert some properties into Dates if they and with <code>At</code>. <code>startAt</code>, <code>createdAt</code> and so on.</p>
  <p>This way I end up with a wrong type.</p>
  <pre><code> type UserRaw = {
      name: string;
      createdAt: string;
  };
  
  const normalizeUser = function (attributes: UserRaw) {
      const normalized = { ...attributes };
      Object.entries(normalized).forEach(([key, value]) =&gt; {
          if (key.endsWith('At')) {
              (normalized as any)[key] = new Date(value as any);
          }
      });
      return normalized;
  }
  
  export type User = ReturnType&lt;typeof normalizeUser&gt;; // this is wrong at this point
  
  </code></pre>
  <p>Can I use some modern TypeScript feature and correct this? I need to map over the keys of the type and detect if the key ends with <code>At</code> and then say the property type is <code>Date</code> instead.</p>