<p dir="auto">Since JSX is a global namespace, it is not possible to use typings declared in a module for its Element or ElementClass.</p>
<p dir="auto">When writing a module, it would then be convenient to write something like ;</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {MyEltType, JSX}  from 'my-custom-jsx-lib'

var myelt = &lt;div&gt; ...&lt;/div&gt;"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-smi">MyEltType</span><span class="pl-kos">,</span> <span class="pl-smi">JSX</span><span class="pl-kos">}</span>  <span class="pl-k">from</span> <span class="pl-s">'my-custom-jsx-lib'</span>

<span class="pl-k">var</span> <span class="pl-s1">myelt</span> <span class="pl-c1">=</span> <span class="pl-c1">&lt;</span><span class="pl-smi">div</span><span class="pl-c1">&gt;</span> ...<span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-s1">div</span><span class="pl-c1">&gt;</span></pre></div>
<p dir="auto">and have typescript check Element, ElementClass and so on on its local JSX instance.</p>
<p dir="auto">Also, when not providing any JSX namespace but having a factory that has a return type, the compiler crashes nastily with a</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/usr/lib/node_modules/typescript/lib/tsc.js:33078
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at isRelatedTo (/usr/lib/node_modules/typescript/lib/tsc.js:16013:32)
    at checkTypeRelatedTo (/usr/lib/node_modules/typescript/lib/tsc.js:15941:26)
    at checkTypeAssignableTo (/usr/lib/node_modules/typescript/lib/tsc.js:15819:20)
    at isTypeAssignableTo (/usr/lib/node_modules/typescript/lib/tsc.js:15813:20)
    at getJsxElementAttributesType (/usr/lib/node_modules/typescript/lib/tsc.js:18463:47)
    at checkJsxOpeningLikeElement (/usr/lib/node_modules/typescript/lib/tsc.js:18564:40)
    at checkJsxSelfClosingElement (/usr/lib/node_modules/typescript/lib/tsc.js:18265:13)
    at checkExpressionWorker (/usr/lib/node_modules/typescript/lib/tsc.js:20439:28)
    at checkExpression (/usr/lib/node_modules/typescript/lib/tsc.js:20349:42)
    at checkExpressionCached (/usr/lib/node_modules/typescript/lib/tsc.js:20310:38)"><pre class="notranslate"><code class="notranslate">/usr/lib/node_modules/typescript/lib/tsc.js:33078
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at isRelatedTo (/usr/lib/node_modules/typescript/lib/tsc.js:16013:32)
    at checkTypeRelatedTo (/usr/lib/node_modules/typescript/lib/tsc.js:15941:26)
    at checkTypeAssignableTo (/usr/lib/node_modules/typescript/lib/tsc.js:15819:20)
    at isTypeAssignableTo (/usr/lib/node_modules/typescript/lib/tsc.js:15813:20)
    at getJsxElementAttributesType (/usr/lib/node_modules/typescript/lib/tsc.js:18463:47)
    at checkJsxOpeningLikeElement (/usr/lib/node_modules/typescript/lib/tsc.js:18564:40)
    at checkJsxSelfClosingElement (/usr/lib/node_modules/typescript/lib/tsc.js:18265:13)
    at checkExpressionWorker (/usr/lib/node_modules/typescript/lib/tsc.js:20439:28)
    at checkExpression (/usr/lib/node_modules/typescript/lib/tsc.js:20349:42)
    at checkExpressionCached (/usr/lib/node_modules/typescript/lib/tsc.js:20310:38)
</code></pre></div>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.2</p>
<p dir="auto"><strong>Code</strong></p>
<p dir="auto">tsconfig.json:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    &quot;compilerOptions&quot;: {
        &quot;jsx&quot;: &quot;react&quot;
    },
    &quot;files&quot;: [
        &quot;app.tsx&quot;
    ]
}"><pre class="notranslate"><code class="notranslate">{
    "compilerOptions": {
        "jsx": "react"
    },
    "files": [
        "app.tsx"
    ]
}
</code></pre></div>
<p dir="auto">app.tsx:</p>
<div class="highlight highlight-source-tsx notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function Test() { }
&lt;Test&gt;&lt;/Test&gt;"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-smi">Test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>
<span class="pl-c1">&lt;</span><span class="pl-smi">Test</span><span class="pl-c1">&gt;</span><span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-smi">Test</span><span class="pl-c1">&gt;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<p dir="auto">Successful compilation, because undefined JSX.Element should be treated as any type.</p>
<p dir="auto"><strong>Actual behavior:</strong></p>
<p dir="auto">Throws exception:<br>
typescript/lib/tsc.js:32989<br>
throw e;<br>
^</p>
<p dir="auto">TypeError: Cannot read property 'flags' of undefined<br>
at isRelatedTo (typescript\lib\tsc.js:15954:32)<br>
at checkTypeRelatedTo (typescript\lib\tsc.js:15882:26)<br>
at checkTypeAssignableTo (typescript\lib\tsc.js:15760:20)<br>
at isTypeAssignableTo (typescript\lib\tsc.js:15754:20)<br>
at getJsxElementAttributesType (typescript\lib\tsc.js:18394:47)<br>
at checkJsxOpeningLikeElement (typescript\lib\tsc.js:18495:40)<br>
at checkJsxElement (typescript\lib\tsc.js:18200:13)<br>
at checkExpressionWorker (typescript\lib\tsc.js:20367:28)<br>
at checkExpression (typescript\lib\tsc.js:20279:42)<br>
at checkExpressionStatement (typescript\lib\tsc.js:21539:13)</p>