Change class type using a TypeScript class decorator
<p>I'm trying to write a TypeScript decorator that is able to modify the class it's applied to. After much experimentation I came to <a href="https://github.com/Microsoft/TypeScript/issues/4881" rel="nofollow">the conclusion it is not yet possible</a>, so I went a different route of using a plain function:</p>

<pre><code>function component&lt;P, T extends { props: P }, C extends { new(): T }&gt;(cls: C) {
  return cls as C &amp; P;
}

const Comp = component(class {
  props = {
    myOptionalString: undefined as string | undefined,
    myNumber: 5 as number,
  };

  static render(elem: typeof Comp) {
    const num: number = elem.myNumber;  // LINE 87
  }
});

const empty: typeof Comp | undefined = undefined;
const c = new Comp();
c.myOptionalString = 'hi';  // LINE 93
</code></pre>

<p>However this too does not work:</p>

<pre><code>ERROR in ./src/index.tsx
(87,30): error TS2339: Property 'myNumber' does not exist on type 'typeof (Anonymous class) &amp; {}'.

ERROR in ./src/index.tsx
(93,3): error TS2339: Property 'myOptionalString' does not exist on type '(Anonymous class)'.
</code></pre>

<p>I'm basically trying to go the route of declaration merging via <code>&amp;</code>, but it isn't working out so far.</p>

<p>Is there any way to mutate a class like this?</p>