title: Get a class (static) property from an instance
body: <p><strong>Updated question:</strong></p>
  
  <p>In a client-side app, I am implementing an event-handling system, similarly to how Redux works.<br>
  I define event types as subclasses of a custom <code>Event</code> class. All such subclasses have their own <code>type</code> static property.<br>
  I trigger an event by creating an instance of a subclass, and sending it to the main handler function.
  In this main handler, I want to use <code>type</code> to decide which specific handler to call.</p>
  
  <p>Since an event is an instance of an Event subclass, I use <code>event.constructor.type</code>.<br>
  It compiles and works fine, but the IDE complains: <code>Property 'type' does not exist on type 'Function'</code> (I also marked it in the code example).</p>
  
  <p>Shall I just ignore the message, or is there a better way to access that static property from an instance?</p>
  
  <pre><code>type State = {};
  
  class Event {
      public static type: string;
  }
  
  class MouseMoveEvent extends Event {
      public static type = "MouseMoveEvent";
      constructor(public x: number, public y: number) {
          super();
      }
  }
  
  class KeypressEvent extends Event {
      public static type = "KeyPressEvent";
      constructor(public key: string) {
          super();
      }
  }
  
  function handleMouseMove(event: MouseMoveEvent, state: State): State {
      // return some new state
  }
  
  function handleKeyPress(event: KeyPressEvent, state: State): State {
      // return some new state
  }
  
  const handlerMap: { [type: string]: (event: Event, state: State) =&gt; State; } = {
      [MouseMoveEvent.type]: (event: Event, state: State) =&gt; handleMouseMove(event as MouseMoveEvent, state),
      [KeyPressEvent.type]: (event: Event, state: State) =&gt; handleKeyPress(event as KeyPressEvent, state)
      // etc.
  };
  
  // The main handler, it receives all triggered events, and decides which specific handler to call, based on the `type` property.
  function handleEvent(event: Event, state: State): State {
      // the editor complains here
      return handlerMap[event.constructor.type](event, state);
  }
  </code></pre>
  
  <p><br></p>
  
  <p><strong>Original question:</strong></p>
  
  <pre><code>class BaseClass {
      public static type: string;
  }
  
  class SubClass1 extends BaseClass {
      public static type = "SubClass1";
  }
  
  class SubClass2 extends BaseClass {
      public static type = "SubClass2";
  }
  
  const map: {[type: string]: number} = {
      [SubClass1.type]: 1,
      [SubClass2.type]: 2
  };
  
  function getNumber(x: BaseClass): number {
      return map[x.constructor.type]; // complains here
  }
  
  const foo = new SubClass1();
  console.log(getNumber(foo));
  </code></pre>
  
  <p>While this code compiles and works (console outputs "SubClass1"), the editor complains: Property 'type' does not exist on type 'Function'.</p>
  
  <p>I tried it in Intellij Idea and the Typescript playground (www.typescriptlang.org/play). Shall I just ignore the editor message, or is there a better way to access that static property from an instance?</p>