<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// ambient.d.ts
declare module 'f' {
    export const enum A {
        A0 = 0,
        A1 = 1
    }
}

// g.ts
import f = require('f');
var a = f.A.A0;"><pre class="notranslate"><span class="pl-c">// ambient.d.ts</span>
<span class="pl-k">declare</span> module <span class="pl-s">'f'</span> <span class="pl-kos">{</span>
    <span class="pl-k">export</span> <span class="pl-k">const</span> <span class="pl-k">enum</span> <span class="pl-smi">A</span> <span class="pl-kos">{</span>
        <span class="pl-c1">A0</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">,</span>
        <span class="pl-c1">A1</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-c">// g.ts</span>
<span class="pl-k">import</span> <span class="pl-s1">f</span> <span class="pl-c1">=</span> require<span class="pl-kos">(</span><span class="pl-s">'f'</span><span class="pl-kos">)</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-s1">f</span><span class="pl-kos">.</span><span class="pl-c1">A</span><span class="pl-kos">.</span><span class="pl-c1">A0</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Run: <code class="notranslate">tsc -m commonjs -t es5 --preserveConstEnums ambient.d.ts g.ts</code></p>
<p dir="auto">Expected output of g.js:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var f = require('f');
var a = f.A.A0;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">f</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'f'</span><span class="pl-kos">)</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-s1">f</span><span class="pl-kos">.</span><span class="pl-c1">A</span><span class="pl-kos">.</span><span class="pl-c1">A0</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Actual output of g.js:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var f = require('f');
var a = 0 /* A0 */;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">f</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'f'</span><span class="pl-kos">)</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">0</span> <span class="pl-c">/* A0 */</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Version: 1.4.1, 1.5.0-pre <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/microsoft/TypeScript/commit/9f49a1637a1afc1f7e0953a5748e5088e91dc777/hovercard" href="https://github.com/microsoft/TypeScript/commit/9f49a1637a1afc1f7e0953a5748e5088e91dc777"><tt>9f49a16</tt></a></p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">nightly (1.9.0-dev.20160430)</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="function foo(options?: { foo?: { bar: string; }; }) {
    if (options &amp;&amp; 'foo' in options) {
        console.log(options.foo.bar); // &lt;-- Object is possibly 'undefined'.
    }
};"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s1">options</span>?: <span class="pl-kos">{</span> <span class="pl-c1">foo</span>?: <span class="pl-kos">{</span> <span class="pl-c1">bar</span>: <span class="pl-smi">string</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">if</span> <span class="pl-kos">(</span><span class="pl-s1">options</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s">'foo'</span> <span class="pl-k">in</span> <span class="pl-s1">options</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">options</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">.</span><span class="pl-c1">bar</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// &lt;-- Object is possibly 'undefined'.</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong></p>
<p dir="auto">No errors.</p>
<p dir="auto"><strong>Actual behavior:</strong></p>
<p dir="auto">With <code class="notranslate">strictNullChecks = true</code> it is reported that the object is possibly <code class="notranslate">undefined</code>.  While <code class="notranslate">options &amp;&amp; options.foo</code> will guard against undefined, it is a common pattern to use <code class="notranslate">'property' in object</code> as a similar guard.</p>