title: Typescript class variables and error: "refers to a value, but is being used as a type here. . Did you mean typeof' ...". Why exactly?
body: <p>This works in Javascript and Typescript:</p>
  <pre class="lang-js prettyprint-override"><code>class A  { /* ... */ }
  const B = class extends A { /* ... */ }
  var x = new B();
  console.log(x instanceof B, x.constructor.name); // true B
  </code></pre>
  <p>But if I try to declare the type of <code>x</code> as <code>B</code>:</p>
  <pre class="lang-js prettyprint-override"><code>var x: B = new B();
  </code></pre>
  <p>I get Typescript Error:</p>
  <blockquote>
  <p>'B' refers to a value, but is being used as a type here. Did you mean 'typeof B'?</p>
  </blockquote>
  <p>(Note, I also get the same error if I replace <code>const B = class extends A { /* ... */ }</code> with simply <code>const B = A</code>, which is what I had originally to make things as simple as possible, but updated on review).</p>
  <p>I don't really understand why this should be the case. According to runtime Javascript <code>x</code> <em>is</em> a <code>B</code> (as shown in the console.log above). And <em>all classes are objects</em> (&quot;values&quot;) under the hood anyway (the Typescript docs themselves equate classes to <a href="https://www.typescriptlang.org/docs/handbook/2/classes.html#static-members" rel="nofollow noreferrer">&quot;constuctor objects&quot;</a>). I'm guessing it's just a limitation of Typescript static analysis - it can't figure out that &quot;B&quot; is a constructor object just like &quot;A&quot; is and track down its typing?</p>
  <p>And also, I don't think so, but wondering, is there actually a way to have this work in Typescript - know B is a constructor object like A and allow the use of B as a type??</p>
  <hr />
  <p>P.S. I realize there are many questions on SO relating to <em>&quot;Blah refers to a value, but is being used as a type here. Did you mean 'typeof Blah'?&quot;</em>, but I couldn't find Q&amp;A approaching it as directly as above. Apologies if I missed it.</p>