<p dir="auto">In some cases, we may want to have a function that read one field of an object identified by a parameter. Here is a small synthetic use case, for the purpose of the discussion:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface Help {
    brief: string;
    detailed: string;
    contextual: string;
}

function getHelpString(help: Help, format: string): string
{
    return help[format];
}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">Help</span> <span class="pl-kos">{</span>
    <span class="pl-c1">brief</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
    <span class="pl-c1">detailed</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
    <span class="pl-c1">contextual</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">getHelpString</span><span class="pl-kos">(</span><span class="pl-s1">help</span>: <span class="pl-smi">Help</span><span class="pl-kos">,</span> <span class="pl-s1">format</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span>: <span class="pl-smi">string</span>
<span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-s1">help</span><span class="pl-kos">[</span><span class="pl-s1">format</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">In that particular case, the type checker cannot ensure that we are doing things right. In order to make the type checker happy, we need a way to tell it that <code class="notranslate">format</code> is actually part of an implicit enumeration that only contains the names of the fields of the interface <code class="notranslate">Help</code>. This could be done by introducing a new type inference operator, for example <code class="notranslate">fieldof</code>.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function getHelpString(help: Help, format: fieldof Help): string
{
    return help[format];
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">getHelpString</span><span class="pl-kos">(</span><span class="pl-s1">help</span>: <span class="pl-smi">Help</span><span class="pl-kos">,</span> <span class="pl-s1">format</span>: <span class="pl-smi">fieldof</span> <span class="pl-smi">Help</span><span class="pl-kos">)</span>: <span class="pl-smi">string</span>
<span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-s1">help</span><span class="pl-kos">[</span><span class="pl-s1">format</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This may not look like a very common use case, but I hoped to have such an operator in order to port incrementally a large amount of javascript code to typescript.</p>
<p dir="auto">When I create a blank node.js console app then in the project properties select "redirect to output folder"  the output continues going to the default location.</p>
<p dir="auto">You can see this in the small project at: <a href="https://github.com/kevinpas/Klib6">https://github.com/kevinpas/Klib6</a><br>
(look at branch AddVS15)</p>