<p dir="auto">Hello TypeScripters.</p>
<p dir="auto">I might be opening a can of worms which might bring an age of darkness upon us (but see PS). Anyway, I've done an attempt to add language support for mixins.</p>
<p dir="auto">For the user, it is similar to the <code class="notranslate">extends</code> or <code class="notranslate">implements</code> keywords, and thus goes by <code class="notranslate">mixes</code>. The semantic intent of the keyword is that a <code class="notranslate">Mixture</code> is NOT a derived class of its <code class="notranslate">Mixins</code>, it just copies their static and dynamic properties.</p>
<p dir="auto">Several mixins can be supplied, the order determines which property will finally be mixed (newer definitions shadow previous definitions).</p>
<p dir="auto">What this does is roughly equivalent to <a href="http://www.typescriptlang.org/Handbook#mixins" rel="nofollow">http://www.typescriptlang.org/Handbook#mixins</a>, except there is no need to copy attributes manually, so mixins become more manageable - hopefully.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
class Base {
    say(hello:string) {
        console.log(hello);
    }
}

class Mixin1 {
    something : string = &quot;Couac couac&quot;;

    fn1() {
            console.log(this.something);
    }
}


class Mixin2 {      
    something : string = &quot;shadowing you, little duck!&quot;;  

    fn2() {
            console.log(&quot;The dragon is&quot;, this.something);
    }
}

/* Only mixes one mixin */
class SimpleMixture mixes Mixin1 {

}

/* Mixes several mixins, property definitions in newer mixins (from left
to right) shadow those from previous mixins AND those in the mixture
class itself, including inherited ones. */
class MultiMixture extends Base mixes Mixin1, Mixin2 {

}


var sm1 = new SimpleMixture();
sm1.fn1();

var sm2 = new MultiMixture();
sm2.fn1();
sm2.fn2();

console.log( sm1 instanceof Base );
console.log( sm1 instanceof Mixin1 );
console.log( sm2 instanceof Base );
console.log( sm2 instanceof Mixin2 );"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Base</span> <span class="pl-kos">{</span>
    <span class="pl-en">say</span><span class="pl-kos">(</span><span class="pl-s1">hello</span>:<span class="pl-smi">string</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">hello</span><span class="pl-kos">)</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">Mixin1</span> <span class="pl-kos">{</span>
    <span class="pl-c1">something</span> : <span class="pl-smi">string</span> <span class="pl-c1">=</span> <span class="pl-s">"Couac couac"</span><span class="pl-kos">;</span>

    <span class="pl-en">fn1</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">something</span><span class="pl-kos">)</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">Mixin2</span> <span class="pl-kos">{</span>      
    <span class="pl-c1">something</span> : <span class="pl-smi">string</span> <span class="pl-c1">=</span> <span class="pl-s">"shadowing you, little duck!"</span><span class="pl-kos">;</span>  

    <span class="pl-en">fn2</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"The dragon is"</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">something</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-c">/* Only mixes one mixin */</span>
<span class="pl-k">class</span> <span class="pl-smi">SimpleMixture</span> <span class="pl-s1">mixes</span> <span class="pl-smi">Mixin1</span> <span class="pl-kos">{</span>

<span class="pl-kos">}</span>

<span class="pl-c">/* Mixes several mixins, property definitions in newer mixins (from left</span>
<span class="pl-c">to right) shadow those from previous mixins AND those in the mixture</span>
<span class="pl-c">class itself, including inherited ones. */</span>
<span class="pl-k">class</span> <span class="pl-smi">MultiMixture</span> <span class="pl-k">extends</span> <span class="pl-smi">Base</span> <span class="pl-s1">mixes</span> <span class="pl-smi">Mixin1</span><span class="pl-kos">,</span> <span class="pl-smi">Mixin2</span> <span class="pl-kos">{</span>

<span class="pl-kos">}</span>


<span class="pl-k">var</span> <span class="pl-s1">sm1</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">SimpleMixture</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">sm1</span><span class="pl-kos">.</span><span class="pl-en">fn1</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">sm2</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">MultiMixture</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">sm2</span><span class="pl-kos">.</span><span class="pl-en">fn1</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">sm2</span><span class="pl-kos">.</span><span class="pl-en">fn2</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span> <span class="pl-s1">sm1</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Base</span> <span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span> <span class="pl-s1">sm1</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Mixin1</span> <span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span> <span class="pl-s1">sm2</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Base</span> <span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span> <span class="pl-s1">sm2</span> <span class="pl-k">instanceof</span> <span class="pl-smi">Mixin2</span> <span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Which emits</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var __applyMixins = this.__applyMixins || function (mixtureTarget) {
    for(var a=1; a&lt;arguments.length; ++a) {
        var mixin = arguments[a];
        Object.getOwnPropertyNames(mixin.prototype).forEach( function(name) {
            mixtureTarget.prototype[name] = mixin.prototype[name];
        })
    }; 
};
var Base = (function () {
    function Base() {
    }
    Base.prototype.say = function (hello) {
        console.log(hello);
    };
    return Base;
})();
var Mixin1 = (function () {
    function Mixin1() {
        this.something = &quot;Couac couac&quot;;
    }
    Mixin1.prototype.fn1 = function () {
        console.log(this.something);
    };
    return Mixin1;
})();
var Mixin2 = (function () {
    function Mixin2() {
        this.something = &quot;shadowing you, little duck!&quot;;
    }
    Mixin2.prototype.fn2 = function () {
        console.log(&quot;The dragon is&quot;, this.something);
    };
    return Mixin2;
})();
/* Only mixes one mixin */
var SimpleMixture = (function () {
    function SimpleMixture() {
        Mixin1.apply(this) ;
    }
    __applyMixins(/*mixtureTarget*/ SimpleMixture, Mixin1);
    return SimpleMixture;
})();
/* Mixes several mixins, property definitions in newer mixins (from left
to right) shadow those from previous mixins AND those in the mixture
class itself, including inherited ones. */
var MultiMixture = (function (_super) {
    __extends(MultiMixture, _super);
    function MultiMixture() {
        _super.apply(this, arguments);
        Mixin1.apply(this) ;
        Mixin2.apply(this) ;
    }
    __applyMixins(/*mixtureTarget*/ MultiMixture, Mixin1, Mixin2);
    return MultiMixture;
})(Base);
var sm1 = new SimpleMixture();
sm1.fn1();
var sm2 = new MultiMixture();
sm2.fn1();
sm2.fn2();
console.log(sm1 instanceof Base);
console.log(sm1 instanceof Mixin1);
console.log(sm2 instanceof Base);
console.log(sm2 instanceof Mixin2);"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">__extends</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">__extends</span> <span class="pl-c1">||</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">d</span><span class="pl-kos">,</span> <span class="pl-s1">b</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">var</span> <span class="pl-s1">p</span> <span class="pl-k">in</span> <span class="pl-s1">b</span><span class="pl-kos">)</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-en">hasOwnProperty</span><span class="pl-kos">(</span><span class="pl-s1">p</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-s1">d</span><span class="pl-kos">[</span><span class="pl-s1">p</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">b</span><span class="pl-kos">[</span><span class="pl-s1">p</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-k">function</span> <span class="pl-c1">__</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span> <span class="pl-c1">=</span> <span class="pl-s1">d</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>
    <span class="pl-c1">__</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span> <span class="pl-c1">=</span> <span class="pl-s1">b</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">;</span>
    <span class="pl-s1">d</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-c1">__</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-k">var</span> <span class="pl-s1">__applyMixins</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">__applyMixins</span> <span class="pl-c1">||</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">mixtureTarget</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">var</span> <span class="pl-s1">a</span><span class="pl-c1">=</span><span class="pl-c1">1</span><span class="pl-kos">;</span> <span class="pl-s1">a</span><span class="pl-c1">&lt;</span><span class="pl-smi">arguments</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span> <span class="pl-c1">++</span><span class="pl-s1">a</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">mixin</span> <span class="pl-c1">=</span> <span class="pl-smi">arguments</span><span class="pl-kos">[</span><span class="pl-s1">a</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
        <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">getOwnPropertyNames</span><span class="pl-kos">(</span><span class="pl-s1">mixin</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">forEach</span><span class="pl-kos">(</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">name</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">mixtureTarget</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">[</span><span class="pl-s1">name</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">mixin</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">[</span><span class="pl-s1">name</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> 
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-v">Base</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">function</span> <span class="pl-v">Base</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">Base</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">say</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">hello</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">hello</span><span class="pl-kos">)</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">Base</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>
<span class="pl-k">var</span> <span class="pl-v">Mixin1</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">function</span> <span class="pl-v">Mixin1</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">something</span> <span class="pl-c1">=</span> <span class="pl-s">"Couac couac"</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-v">Mixin1</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">fn1</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-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">something</span><span class="pl-kos">)</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">Mixin1</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>
<span class="pl-k">var</span> <span class="pl-v">Mixin2</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">function</span> <span class="pl-v">Mixin2</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">something</span> <span class="pl-c1">=</span> <span class="pl-s">"shadowing you, little duck!"</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-v">Mixin2</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">.</span><span class="pl-en">fn2</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-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"The dragon is"</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">something</span><span class="pl-kos">)</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">Mixin2</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>
<span class="pl-c">/* Only mixes one mixin */</span>
<span class="pl-k">var</span> <span class="pl-v">SimpleMixture</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">function</span> <span class="pl-v">SimpleMixture</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-v">Mixin1</span><span class="pl-kos">.</span><span class="pl-en">apply</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-kos">}</span>
    <span class="pl-s1">__applyMixins</span><span class="pl-kos">(</span><span class="pl-c">/*mixtureTarget*/</span> <span class="pl-v">SimpleMixture</span><span class="pl-kos">,</span> <span class="pl-v">Mixin1</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-v">SimpleMixture</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>
<span class="pl-c">/* Mixes several mixins, property definitions in newer mixins (from left</span>
<span class="pl-c">to right) shadow those from previous mixins AND those in the mixture</span>
<span class="pl-c">class itself, including inherited ones. */</span>
<span class="pl-k">var</span> <span class="pl-v">MultiMixture</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-s1">_super</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-s1">__extends</span><span class="pl-kos">(</span><span class="pl-v">MultiMixture</span><span class="pl-kos">,</span> <span class="pl-s1">_super</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">function</span> <span class="pl-v">MultiMixture</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">_super</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-smi">arguments</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-v">Mixin1</span><span class="pl-kos">.</span><span class="pl-en">apply</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-v">Mixin2</span><span class="pl-kos">.</span><span class="pl-en">apply</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-kos">}</span>
    <span class="pl-s1">__applyMixins</span><span class="pl-kos">(</span><span class="pl-c">/*mixtureTarget*/</span> <span class="pl-v">MultiMixture</span><span class="pl-kos">,</span> <span class="pl-v">Mixin1</span><span class="pl-kos">,</span> <span class="pl-v">Mixin2</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-v">MultiMixture</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">Base</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">sm1</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">SimpleMixture</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">sm1</span><span class="pl-kos">.</span><span class="pl-en">fn1</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">sm2</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">MultiMixture</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">sm2</span><span class="pl-kos">.</span><span class="pl-en">fn1</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">sm2</span><span class="pl-kos">.</span><span class="pl-en">fn2</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">sm1</span> <span class="pl-k">instanceof</span> <span class="pl-v">Base</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">sm1</span> <span class="pl-k">instanceof</span> <span class="pl-v">Mixin1</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">sm2</span> <span class="pl-k">instanceof</span> <span class="pl-v">Base</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">sm2</span> <span class="pl-k">instanceof</span> <span class="pl-v">Mixin2</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">and outputs</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; Couac couac
&gt;&gt;&gt; shadowing you, little duck!
&gt;&gt;&gt; The dragon is shadowing you, little duck!
&gt;&gt;&gt; false
&gt;&gt;&gt; false
&gt;&gt;&gt; true
&gt;&gt;&gt; false"><pre class="notranslate">&gt;&gt;&gt; Couac couac
&gt;&gt;&gt; shadowing you, little duck<span class="pl-k">!</span>
&gt;&gt;&gt; The dragon is shadowing you, little duck<span class="pl-k">!</span>
&gt;&gt;&gt; <span class="pl-c1">false</span>
&gt;&gt;&gt; <span class="pl-c1">false</span>
&gt;&gt;&gt; <span class="pl-c1">true</span>
&gt;&gt;&gt; <span class="pl-c1">false</span></pre></div>
<p dir="auto">At this point it seems to work with target ES&lt;6 with quite some limitations (the user can't pass arguments to the mixin constructors). Type checking seems to be working (although I could not make Eclipse or Emacs behave with the new keyword). But be warned Very early experimental preview code from a bad JS programmer who knew nothing about TSC's internals three days ago and who was in a rush. Be warned.</p>
<p dir="auto">I did this to overcome a maintainability issue with my code and rushed this implementation. It was also an exercise to learn more about TSC. I'm also aware that it might not be a great idea to add keywords to a language each time one gets into trouble, but if others see interest in it or you have suggestions, the branch is here <a href="https://github.com/dbarbeau/TypeScript/tree/mixes">https://github.com/dbarbeau/TypeScript/tree/mixes</a>. Just don't expect this implementation to be stable/complete/anything. Actually, if it can just spark some interest/discussion on how to make mixins more useable, then I'm ok with that.</p>
<p dir="auto">Daniel<br>
PS: Don't get mad at me :)<br>
PS: I'm now testing this with more "serious code", I will quickly see if it is indeed practical.</p>
<p dir="auto">As per ES6 grammar:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export VariableStatement
export Declaration
export default HoistableDeclaration[Default]
export default [lookahead ≠ function ] AssignmentExpression[In] ;


ExportClause[NoReference] :
{ }
{ ExportsList }
{ ExportsList , }

ExportsList :
ExportSpecifier
ExportsList , ExportSpecifier

ExportSpecifier :
IdentifierName
IdentifierName as IdentifierName

FromClause :
from ModuleSpecifier

ModuleSpecifier :
StringLiteral"><pre class="notranslate"><code class="notranslate">ExportDeclaration :
export * FromClause ;
export ExportClause FromClause ;
export ExportClause ;
export VariableStatement
export Declaration
export default HoistableDeclaration[Default]
export default [lookahead ≠ function ] AssignmentExpression[In] ;


ExportClause[NoReference] :
{ }
{ ExportsList }
{ ExportsList , }

ExportsList :
ExportSpecifier
ExportsList , ExportSpecifier

ExportSpecifier :
IdentifierName
IdentifierName as IdentifierName

FromClause :
from ModuleSpecifier

ModuleSpecifier :
StringLiteral
</code></pre></div>
<p dir="auto">Meanings of export syntax that we currently do not support (doesn't list generators since we do not support them as yet)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export default function name() { } 
// function name() { } 
// exports.default = name;"><pre class="notranslate"><code class="notranslate">export default function name() { } 
// function name() { } 
// exports.default = name;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export default function () { } 
// function _temp() { } 
// exports.default = _temp;"><pre class="notranslate"><code class="notranslate">export default function () { } 
// function _temp() { } 
// exports.default = _temp;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export default = expression; 
// var _tmp = expression;
// exports.default = _tmp;"><pre class="notranslate"><code class="notranslate">export default = expression; 
// var _tmp = expression;
// exports.default = _tmp;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export { }; 
// Make this external module"><pre class="notranslate"><code class="notranslate">export { }; 
// Make this external module
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export { } from StringLiteral; 
// import __tmp = require(StringLiteral)"><pre class="notranslate"><code class="notranslate">export { } from StringLiteral; 
// import __tmp = require(StringLiteral)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export { a }; 
//exports.a = a;"><pre class="notranslate"><code class="notranslate">export { a }; 
//exports.a = a;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export { a } from StringLiteral; 
// import __tmp = require(StringLiteral)
// exports.a = _tmp.a"><pre class="notranslate"><code class="notranslate">export { a } from StringLiteral; 
// import __tmp = require(StringLiteral)
// exports.a = _tmp.a
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export { id1 as a}; 
//exports.a = id1;"><pre class="notranslate"><code class="notranslate">export { id1 as a}; 
//exports.a = id1;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export { id1 as a } from StringLiteral; 
// import __tmp = require(StringLiteral)
// exports.a = _tmp.id1"><pre class="notranslate"><code class="notranslate">export { id1 as a } from StringLiteral; 
// import __tmp = require(StringLiteral)
// exports.a = _tmp.id1
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="export * from StringLiteral
// import _tmp = require(StringLIteral)
// foreach(a in _tmp.exports) 
// exports.a = _tmp.exports[a] "><pre class="notranslate"><code class="notranslate">export * from StringLiteral
// import _tmp = require(StringLIteral)
// foreach(a in _tmp.exports) 
// exports.a = _tmp.exports[a] 
</code></pre></div>
<p dir="auto">Few things to consider:</p>
<ol dir="auto">
<li>Resolution of export name is as follows,</li>
</ol>
<ul dir="auto">
<li>if the name is directly exported clause (without referring to another module) - the resolution is returned for this name</li>
<li>if the name is exported using names eg. export {a} from stringLiteral  - that resolution is returned</li>
<li>it is tried to be resolved from export entries of name (except default) from export * from StringLiteral</li>
<li>Should we be reporting errors for the name from export * from StringLiteral that is shadowed by the local exports/indirect named exports/existing * exports. According to ES6 it is ok, but should we still report error for shadowing for unintentional cases?</li>
</ul>
<ol dir="auto">
<li>The export names are always resolved in order of local exports, indirect exports and then star exports, But typescript currently uses declaration order to determine duplicate error. Should we change this order for duplicate naming or is it ok?</li>
</ol>