title: How to represent the type of a value in Typescript?
body: <p>How do I represent an arbitrary type of value in Typescript? For example:</p>
  <pre><code>class Checker {
    /**
     * @param first a value
     * @param second the type of a value
     * @return true if &quot;first&quot; is an instance of type &quot;second&quot;
     */
    public instanceOf(first: unknown, second: Class): boolean {
      return first instanceof second;
    }
  }
  </code></pre>
  <p>The above code has to behave the same as <code>first instanceof second</code> but I can't figure out what type <code>second</code> must have to make this work.</p>
  <p>This question is related to <a href="https://stackoverflow.com/q/39392853/14731">Is there a type for &quot;Class&quot; in Typescript? And does &quot;any&quot; include it?</a> but none of the answers work for classes with private constructors (e.g. <a href="https://js-joda.github.io/js-joda/manual/LocalDate.html" rel="nofollow noreferrer">LocalDate</a>). I cannot simply change the constructor to public because users must be able to pass in values from third-party libraries.</p>
  <h2>What doesn't work</h2>
  <ul>
  <li><code>new (...args: never[]) =&gt; unknown)</code> fails with:</li>
  </ul>
  <blockquote>
  <p>Cannot assign a 'private' constructor type to a 'public' constructor type.</p>
  </blockquote>
  <ul>
  <li><p><code>public instanceOf&lt;T&gt;(first: unknown, second: T)</code> does not work because it allows users to pass non-type values into <code>second</code> such as <code>1234</code> or <code>&quot;test&quot;</code>. Remember, if <code>first instanceof 1234</code> results in a compiler error then so should <code>instanceOf(first, 1234)</code>.</p>
  </li>
  <li><p><code>public instanceOf&lt;T extends object&gt;(first: unknown, second: T)</code> blocks non-type values but then the method implementation fails to compile with:</p>
  </li>
  </ul>
  <blockquote>
  <p>TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.</p>
  </blockquote>