<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.9.0-dev</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="// A self-contained demonstration of the problem follows...
interface A {}
interface B {}
interface C {}
declare function isA(arg: any): arg is A;
declare function isB(arg: any): arg is B;
declare function isC(arg: any): arg is C;

function handleAction&lt;T&gt;(action: T) {
  switch (true) {
    case isA(action):
    case isB(action):
      // action expected to be A|B type here
      break;
    case isC(action):
      // action expected to be C type here
      break;
    default:
      // action expected to be undefined type here
  }
}"><pre class="notranslate"><span class="pl-c">// A self-contained demonstration of the problem follows...</span>
<span class="pl-k">interface</span> <span class="pl-smi">A</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">interface</span> <span class="pl-smi">B</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">interface</span> <span class="pl-smi">C</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">isA</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span>: <span class="pl-s1">arg</span> is <span class="pl-smi">A</span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">isB</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span>: <span class="pl-s1">arg</span> is <span class="pl-smi">B</span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">isC</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span>: <span class="pl-s1">arg</span> is <span class="pl-smi">C</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">handleAction</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">action</span>: <span class="pl-smi">T</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">case</span> <span class="pl-en">isA</span><span class="pl-kos">(</span><span class="pl-s1">action</span><span class="pl-kos">)</span>:
    <span class="pl-k">case</span> <span class="pl-en">isB</span><span class="pl-kos">(</span><span class="pl-s1">action</span><span class="pl-kos">)</span>:
      <span class="pl-c">// action expected to be A|B type here</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>
    <span class="pl-k">case</span> <span class="pl-en">isC</span><span class="pl-kos">(</span><span class="pl-s1">action</span><span class="pl-kos">)</span>:
      <span class="pl-c">// action expected to be C type here</span>
      <span class="pl-k">break</span><span class="pl-kos">;</span>
    <span class="pl-k">default</span>:
      <span class="pl-c">// action expected to be undefined type here</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Typescript supports type aliases since 1.4.</p>
<p dir="auto">In order to achieve better abstraction patterns and to enhance tooling, it would be nice to have a more extended alias syntax in typescript.</p>
<p dir="auto">One current issue of not having aliases for other typescript constructs, like modules and interfaces, is code fragmentation in the generated declaration files, as they often end up describing the same construct multiple times in one file, referenced by a common name.</p>
<p dir="auto">For example, the typescript.d.ts declaration file contains 6 occurences of the same "typescript" module. Aliases could allow here to differentiate the different intended sections of the typescript module in the declaration file.</p>
<p dir="auto">The "as" syntax already exists in ecmascript 6 for importing modules:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import * as lib from 'lib';"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">lib</span> <span class="pl-k">from</span> <span class="pl-s">'lib'</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">We could extend this syntax for aliases in typescript, and this optional feature could enhance all nodes having the ability to be duplicated in code, like interfaces and modules, as well as type definitions, ambient declarations, exports and original javascript nodes.</p>
<p dir="auto">typescript constructs:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare module &quot;moduleName&quot; as moduleAlias

module &quot;moduleName&quot; as moduleAlias

type typeName as typeAlias

interface interfaceName as interfaceAlias
"><pre class="notranslate"><span class="pl-s1">declare</span> <span class="pl-smi">module</span> <span class="pl-s">"moduleName"</span> <span class="pl-s1">as</span> <span class="pl-s1">moduleAlias</span>

<span class="pl-smi">module</span><span class="pl-kos"></span> <span class="pl-s">"moduleName"</span> <span class="pl-s1">as</span> <span class="pl-s1">moduleAlias</span>

<span class="pl-s1">type</span> <span class="pl-s1">typeName</span> <span class="pl-k">as</span> <span class="pl-s1">typeAlias</span>

<span class="pl-s1">interface</span> <span class="pl-s1">interfaceName</span> <span class="pl-k">as</span> <span class="pl-s1">interfaceAlias</span></pre></div>
<p dir="auto">javascript nodes:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
export class className as classAlias

class className as classAlias

function functionName() as functionAlias {};

let var1 as letAlias

var var2 as varAlias"><pre class="notranslate"><span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-s1">className</span> <span class="pl-s1">as</span> <span class="pl-s1">classAlias</span>

<span class="pl-s1">class</span> <span class="pl-s1">className</span> <span class="pl-s1">as</span> <span class="pl-s1">classAlias</span>

<span class="pl-s1">function</span> <span class="pl-s1">functionName</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-k">as</span> <span class="pl-s1">functionAlias</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">let</span> <span class="pl-s1">var1</span> <span class="pl-s1">as</span> <span class="pl-s1">letAlias</span>

<span class="pl-k">var</span> <span class="pl-s1">var2</span> <span class="pl-s1">as</span> <span class="pl-s1">varAlias</span></pre></div>
<p dir="auto">The extended "as" syntax would not affect the resulting javascript code, it would only serve as a typescript abstraction.</p>