title: How to feature flag/toggle TypeScript service/class
body: <p>I would like to feature flag a service in my React app so I can toggle it on and off by changing a boolean in a config file. However, I am unsure as to how best to do so. The service is as below:</p>
  <pre><code>class Service {
    constructor() {
      // do stuff
    }
  
    doA() {
      // do stuff
    }
  
    doB() {
      // do stuff
    }
  
    // more methods
  }
  
  export const serviceInstance = new Service();
  </code></pre>
  <p>This service's methods are called in different parts of the application.</p>
  <p>Currently, I am flagging it by creating another class with the same methods and attributes as <code>Service</code> and then exporting the relevant instance based on the feature flag boolean:</p>
  <pre><code>class ServiceMock {
    constructor() {
      return;
    }
  
    doA() {
      return;
    }
  
    doB() {
      return;
    }
  
    // more empty return methods
  }
  
  export const serviceInstance = serviceFlag ? new Service() : new ServiceMock();
  </code></pre>
  <p>It works but I am worried that this is rather inefficient, especially when the number of methods and attributes grow. Is there a better way to feature flag something like this?</p>