title: How to make a generic type an union type of Record<K,V> and an interface in Typescript?
body: <p>I want to declare a couple singleton class (Angular service) that <em>must</em> have some members named after an enum. Until now I had it as a const:</p>
  
  <pre><code>enum RewardId {
    HEHE = 'AdMobRewardIdHEHE',
    HOHO = 'AdMobRewardIdHOHO',
  }
  
  interface RewardObject {
    id: RewardId;
    someData: any
  }
  
  
  const MyConst: Record&lt;RewardId, RewardObject&gt; = {
    [RewardId.HEHE]: {
      id: RewardId.HEHE,
      someData: 'someData'
    },
  
    [RewardId.HOHO]: {
      id: RewardId.HOHO,
      someData: 'someData'
    }
  }
  
  </code></pre>
  
  <p>If I add a new <code>RewardId</code> Typescript lets me know that I have to implement it on <code>MyConst</code> <strong>this is what I want</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Twyw9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Twyw9.png" alt="enter image description here"></a>
  [Typescript Playground link][2]</p>
  
  <p>Now, I want to change it to a service (so a class) because it is easier to test and I also need some methods there.</p>
  
  <pre><code>interface VaultMethods {
     someMethod1(): void;
    someMethod2(): void;
  }
  
  class MyClass implements Record&lt;RewardId, RewardObject&gt;, VaultMethods {
    [RewardId.HEHE] = {
      id: RewardId.HEHE,
      someData: 'someData'
    };
  
    [RewardId.HOHO] = {
      id: RewardId.HOHO,
      someData: 'someData'
    };
  
    someMethod1() { }
  
    someMethod2() { }
  }
  </code></pre>
  
  <p>[Typescript Playground][3]</p>
  
  <p>As final step I need this to convert that class definition in a generic interface:</p>
  
  <p>This does not work <code>interface Vault&lt;K, V&gt; extends VaultMethods, Record&lt;K, V&gt;</code> because <code>An interface can only extend an object type or intersection of object types with statically known members.</code></p>
  
  <p>If I make it a type it kind of works in the way that Typescript ask me to implement the methods and members </p>
  
  <pre><code>type Vault&lt;K, V&gt; = Record&lt;K, V&gt; &amp; VaultMethods;
  class MyClass2 implements Vault&lt;RewardId, RewardObject&gt; {
  
  }
  </code></pre>
  
  <p><a href="https://www.typescriptlang.org/play/?ssl=68&amp;ssc=2&amp;pln=49&amp;pc=1#code/KYOwrgtgBASsDuBDATgEwJKqgbwLACgooAJAUTKgF4oByAQVQFkB7AIziTUzLJoBoCRYgHkRVWgxbsEKDKhEj+BAgF9l+AJYgALsGQAzRAGNgsGWmGsAVsCPacgqBtQAuM5zkBuRwGdmEYAARRG1EN0QQAE9VdSNmEB97RkiAYXjEtzg4tAAeDllMPndZSxs7AD5xPEIoAG18rlQAOh5SAF03aqIiZ0zzORbyUgEaoj8A4NC3GnGgkMQaRxURx3r+zBbRYQ6HUadXYsbNkRHuqFnJsNoL+cWatXwH9S1dA2NTADVEMAAbbUZgNoABbMVA+XbdWYA4GggCMAAoAJRuABuzGc3hqUMBINQACYkaj0ahMU98EYfogfODkilKdSnBAAA4-YABHTgrLMXINORFXmlWzacpFL6-f440Hgrp1XkbVptKqOHoHOXNVqnSH+OZTa7ay53IgqTGrNXHbZKva9Q4DBTCTVjfXzaY3UKGqDG9SOgLQ3EIxE4D1e87a32ggkB7BBx7qAgAejjiWQWgA5lBgAAPXQgMFQAAqUAA-IHagAFJwgfM7NEYj1QNx5zxEBNQUjIZDc9TaSJMz7fP5c3IAaXTWdAuYA1sBIsx9FAIpEinnKtQZUQyxWoEOdo3VCb8N3e1AxX8ckPRSvj-3tIPUGeL1AAGRX8VhsH7ilUmmpek+PGMlk2VAbRwRPbQ8nWVB+X6QUKghWVIMGMhFVXZV9j6Dx5SGB0QwmZ09Twt0ln3dczTtFD4JVDCCnVLYcNdK4ZidIj7hI71gDff0cE9LFQ0lfEkW40kgA" rel="nofollow noreferrer">Typescript Playground</a>
  <a href="https://i.stack.imgur.com/NaI0L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NaI0L.png" alt="as type"></a></p>
  
  <p>But It shows an error in the Type Definition:
  <a href="https://i.stack.imgur.com/cJn4E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cJn4E.png" alt="error in the Type Definition"></a></p>
  
  <p>Is there a way to fix this?</p>