<p dir="auto">Hi all,</p>
<p dir="auto">I have a collection of TypeScript files that, on Windows, compile under tsc when run under node, but throw bogus errors (I can clearly see the source contradicts them) when compiled via the Visual Studio TypeScript 1.7.6.0 extension which uses tsc.exe.  I implemented a very temporary workaround by creating my own <code class="notranslate">tsc.exe</code> which simply invokes the compiler via node and overrwrote the default <code class="notranslate">tsc.exe</code>, found in <code class="notranslate">c:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\</code> with my own.</p>
<p dir="auto">It would be great if the Visual Studio extension allowed the user the option to specify the compiler implementation to use, Node or tsc.exe.</p>
<p dir="auto">Consider this implmentation of a ORM-like Model class:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
class Model {
    public static tableName: string;
    public static findById(id: number): this { // error: a this type is only available in a non-static member of a class or interface 
        const rows = db.query(`SELECT * FROM ${this.tableName} WHERE id = ?`, [id]);
        const instance = new this();
        for (const column of rows[0]) {
            instance[column] = rows[0][column];
        }
        return instance;        
    }
}

class User extends Model {
    public static tableName = 'users';
    public username: string;    
}

const user = User.findById(1); // user instanceof User"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Model</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-c1">tableName</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
    <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-en">findById</span><span class="pl-kos">(</span><span class="pl-s1">id</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: this <span class="pl-kos">{</span> <span class="pl-c">// error: a this type is only available in a non-static member of a class or interface </span>
        <span class="pl-k">const</span> <span class="pl-s1">rows</span> <span class="pl-c1">=</span> <span class="pl-s1">db</span><span class="pl-kos">.</span><span class="pl-en">query</span><span class="pl-kos">(</span><span class="pl-s">`SELECT * FROM <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">tableName</span><span class="pl-kos">}</span></span> WHERE id = ?`</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s1">id</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">const</span> <span class="pl-s1">instance</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">this</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">const</span> <span class="pl-s1">column</span> <span class="pl-k">of</span> <span class="pl-s1">rows</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">instance</span><span class="pl-kos">[</span><span class="pl-s1">column</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">rows</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">[</span><span class="pl-s1">column</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-k">return</span> <span class="pl-s1">instance</span><span class="pl-kos">;</span>        
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">User</span> <span class="pl-k">extends</span> <span class="pl-smi">Model</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-c1">tableName</span> <span class="pl-c1">=</span> <span class="pl-s">'users'</span><span class="pl-kos">;</span>
    <span class="pl-k">public</span> <span class="pl-c1">username</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>    
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">user</span> <span class="pl-c1">=</span> <span class="pl-smi">User</span><span class="pl-kos">.</span><span class="pl-en">findById</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// user instanceof User</span></pre></div>
<p dir="auto">Currently, this is not possible, because TypeScript does not allow <code class="notranslate">this</code> in static members. There is no reason for this limitation: <code class="notranslate">this</code> inside a static method is simply the class in JavaScript (aka <code class="notranslate">typeof Model</code> or <code class="notranslate">typeof User</code>, depending on what class this is called on).</p>