<p dir="auto">HI, i wanted to look at typescript and saw, that private members are not really private in console :D<br>
i searched in your FAQ and found an entry to this, but i think this might be a solution for private members.</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.9</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
// you all know it:
class Foo {
  private x = 0;
  increment(): number {
      this.x++;
      return x;
  }
}"><pre class="notranslate"><span class="pl-c">// you all know it:</span>
<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
  <span class="pl-k">private</span> <span class="pl-c1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
  <span class="pl-en">increment</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">number</span> <span class="pl-kos">{</span>
      <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">x</span><span class="pl-c1">++</span><span class="pl-kos">;</span>
      <span class="pl-k">return</span> <span class="pl-s1">x</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Wished behavior:</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// what about something like this?
var Foo = (function () {
    var privates = {};

    function Foo() {
        privates[ this ] = { x: 0 };
    }

    Foo.prototype.increment = function () {
        privates[ this ].x++;
        return privates[ this ].x;
    };
    return Foo;
})();"><pre class="notranslate"><span class="pl-c">// what about something like this?</span>
<span class="pl-k">var</span> <span class="pl-v">Foo</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">privates</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span>

    <span class="pl-k">function</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">privates</span><span class="pl-kos">[</span> <span class="pl-smi">this</span> <span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span> <span class="pl-c1">x</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-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">increment</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">privates</span><span class="pl-kos">[</span> <span class="pl-smi">this</span> <span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">x</span><span class="pl-c1">++</span><span class="pl-kos">;</span>
        <span class="pl-k">return</span> <span class="pl-s1">privates</span><span class="pl-kos">[</span> <span class="pl-smi">this</span> <span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-c1">x</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-v">Foo</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Actual behavior:</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="

// generates
var Foo = (function () {
    var x = 0;

    function Foo() {
    }
    Foo.prototype.increment = function () {
        x++;
        return x;
    };
    return Foo;
})();"><pre class="notranslate"><span class="pl-c">// generates</span>
<span class="pl-k">var</span> <span class="pl-v">Foo</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>

    <span class="pl-k">function</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-kos">}</span>
    <span class="pl-v">Foo</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">increment</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">x</span><span class="pl-c1">++</span><span class="pl-kos">;</span>
        <span class="pl-k">return</span> <span class="pl-s1">x</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-v">Foo</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Consider the following code</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export class Test {
    private x: number;
    constructor() {
        this.x = 42;
    }
    f() : number {
        return this.x;
    }
}"><pre class="notranslate"><code class="notranslate">export class Test {
    private x: number;
    constructor() {
        this.x = 42;
    }
    f() : number {
        return this.x;
    }
}
</code></pre></div>
<p dir="auto">Typescript generates the following JS</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var Test = (function () {
    function Test() {
        this.x = 42;
    }
    Test.prototype.f = function () {
        return this.x;
    };
    return Test;
})();
exports.Test = Test;"><pre class="notranslate"><code class="notranslate">var Test = (function () {
    function Test() {
        this.x = 42;
    }
    Test.prototype.f = function () {
        return this.x;
    };
    return Test;
})();
exports.Test = Test;
</code></pre></div>
<p dir="auto">Obviously, one could run something like <code class="notranslate">new Test().x</code> in a JS library, and <code class="notranslate">private</code> invariant would fail. I think it's not a kind of behaviour one would expect from <code class="notranslate">private</code>, at least in <code class="notranslate">export</code>ed classes. The fix is quite simple:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var Test = (function () {
    var _private = {};
    function Test() {
        _private.x = 42;
    }
    Test.prototype.f = function () {
        return _private.x;
    };
    return Test;
})();
exports.Test = Test;"><pre class="notranslate"><code class="notranslate">var Test = (function () {
    var _private = {};
    function Test() {
        _private.x = 42;
    }
    Test.prototype.f = function () {
        return _private.x;
    };
    return Test;
})();
exports.Test = Test;
</code></pre></div>