<p dir="auto">I think I have noticed a problem with Generic Methods, not properly inferring their types, when they are used as a value, instead of as a method.   I'm not sure if it's a known issue or not.</p>
<p dir="auto">It's easy enough to work around by using a function, but I'd prefer to just hand in the method, since it's already a method that can be called.</p>
<p dir="auto">This case is in Rx, but I've seen other examples of it too.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var observableOfAny = Observable.from(items)
    .flatMap(Observable.from); // using as a variable doesn't work

var observableOfString = Observable.from(items)
    .flatMap(x =&gt; Observable.from(x)); // Using a delegate works

var fromString: (arr: string[]) =&gt; Observable&lt;string&gt; = Observable.from;
var observableOfString = Observable.from(items)
    .flatMap(fromString); // Properly casting the method works"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">observableOfAny</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">from</span><span class="pl-kos">(</span><span class="pl-s1">items</span><span class="pl-kos">)</span>
    <span class="pl-kos">.</span><span class="pl-en">flatMap</span><span class="pl-kos">(</span><span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-c1">from</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// using as a variable doesn't work</span>

<span class="pl-k">var</span> <span class="pl-s1">observableOfString</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">from</span><span class="pl-kos">(</span><span class="pl-s1">items</span><span class="pl-kos">)</span>
    <span class="pl-kos">.</span><span class="pl-en">flatMap</span><span class="pl-kos">(</span><span class="pl-s1">x</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">from</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// Using a delegate works</span>

<span class="pl-k">var</span> <span class="pl-s1">fromString</span>: <span class="pl-kos">(</span><span class="pl-s1">arr</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-c1">=&gt;</span> <span class="pl-smi">Observable</span><span class="pl-kos">&lt;</span><span class="pl-smi">string</span><span class="pl-kos">&gt;</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-c1">from</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">observableOfString</span> <span class="pl-c1">=</span> <span class="pl-smi">Observable</span><span class="pl-kos">.</span><span class="pl-en">from</span><span class="pl-kos">(</span><span class="pl-s1">items</span><span class="pl-kos">)</span>
    <span class="pl-kos">.</span><span class="pl-en">flatMap</span><span class="pl-kos">(</span><span class="pl-s1">fromString</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// Properly casting the method works</span></pre></div>
<p dir="auto">I've got an example, again using rx interfaces (so maybe something is wrong with them? it's possible).  <a href="http://www.typescriptlang.org/Playground#src=%2F%2F%20Type%20alias%20for%20observables%20and%20promises%0Atype%20ObservableOrPromise%3CT%3E%20%3D%20IObservable%3CT%3E%20%7C%20Observable%3CT%3E%20%7C%20Promise%3CT%3E%3B%0A%2F%2Ftype%20ArrayLike%3CT%3E%20%3D%20Array%3CT%3E%20%7C%20%7B%20length%3A%20number%3B%5Bindex%3A%20number%5D%3A%20T%3B%20%7D%3B%0A%2F%2F%20Type%20alias%20for%20arrays%20and%20array%20like%20objects%0Atype%20ArrayOrIterable%3CT%3E%20%3D%20ArrayLike%3CT%3E%3B%0Ainterface%20Promise%3CT%3E%20%7B%0A%20%20%20%20then%3CR%3E%28onFulfilled%3A%20%28value%3A%20T%29%20%3D%3E%20R%7CPromise%3CR%3E%2C%20onRejected%3A%20%28error%3A%20any%29%20%3D%3E%20Promise%3CR%3E%29%3A%20Promise%3CR%3E%3B%0A%20%20%20%20then%3CR%3E%28onFulfilled%3A%20%28value%3A%20T%29%20%3D%3E%20R%7CPromise%3CR%3E%2C%20onRejected%3F%3A%20%28error%3A%20any%29%20%3D%3E%20R%29%3A%20Promise%3CR%3E%3B%0A%7D%0Ainterface%20IPromise%3CT%3E%20extends%20Promise%3CT%3E%20%7B%20%7D%0Aexport%20type%20_Selector%3CT%2C%20TResult%3E%20%3D%20%28value%3A%20T%2C%20index%3A%20number%2C%20observable%3A%20Observable%3CT%3E%29%20%3D%3E%20TResult%3B%0Aexport%20type%20_ValueOrSelector%3CT%2C%20TResult%3E%20%3D%20TResult%20%7C%20_Selector%3CT%2C%20TResult%3E%3B%0Ainterface%20IObservable%3CT%3E%20%7B%20%7D%0Ainterface%20Observable%3CT%3E%20%7B%0A%20%20%20%20flatMap%3CTResult%3E%28selector%3A%20_ValueOrSelector%3CT%2C%20ObservableOrPromise%3CTResult%3E%3E%29%3A%20Observable%3CTResult%3E%3B%0A%20%20%20%20toArray%28%29%3A%20Observable%3CT%5B%5D%3E%3B%0A%7D%0Aexport%20interface%20ObservableStatic%20%7B%0A%20%20%20%20from%3CT%3E%28array%3A%20ArrayOrIterable%3CT%3E%29%3A%20Observable%3CT%3E%3B%0A%7D%0Aexport%20var%20Observable%3A%20ObservableStatic%3B%0Avar%20fromString%3A%20%28arr%3A%20string%5B%5D%29%20%3D%3E%20Observable%3Cstring%3E%20%3D%20Observable.from%3B%0A%0Avar%20items%20%3D%20%5B'1'%2C'2'%2C'3'%5D%3B%0A%0Avar%20observableOfAny%20%3D%20Observable.from%28items%29%0A%20%20%20%20.flatMap%28Observable.from%29%3B%0A%0Avar%20observableOfAny%20%3D%20Observable.from%28items%29%0A%20%20%20%20.flatMap%28x%20%3D%3E%20Observable.from%28x%29%29%3B%0A%0Avar%20observableOfAny%20%3D%20Observable.from%28items%29%0A%20%20%20%20.flatMap%28fromString%29%3B%0A%0A%0A" rel="nofollow">playground example</a></p>
<p dir="auto">The following code snippet compiles without type errors though the type variable <code class="notranslate">T</code> is constrained to <code class="notranslate">string</code> type.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
function foo1(f: (s: string) =&gt; string)
{
    return f(&quot;hello world&quot;);
}

function foo2(f: (s: number) =&gt; number)
{
    return f(123);
}

function genericBar&lt;T extends string&gt;(arg: T): T
{
    return arg;
}

var x1 = foo1(genericBar);
var x2 = foo2(genericBar);"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">foo1</span><span class="pl-kos">(</span><span class="pl-s1">f</span>: <span class="pl-kos">(</span><span class="pl-s1">s</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">string</span><span class="pl-kos">)</span>
<span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s">"hello world"</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-en">foo2</span><span class="pl-kos">(</span><span class="pl-s1">f</span>: <span class="pl-kos">(</span><span class="pl-s1">s</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">number</span><span class="pl-kos">)</span>
<span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-c1">123</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-en">genericBar</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span> <span class="pl-k">extends</span> <span class="pl-smi">string</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">T</span><span class="pl-kos">)</span>: <span class="pl-smi">T</span>
<span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-s1">arg</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">var</span> <span class="pl-s1">x1</span> <span class="pl-c1">=</span> <span class="pl-en">foo1</span><span class="pl-kos">(</span><span class="pl-s1">genericBar</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">x2</span> <span class="pl-c1">=</span> <span class="pl-en">foo2</span><span class="pl-kos">(</span><span class="pl-s1">genericBar</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Non generic version <code class="notranslate">nonGenericBar</code> works as expected.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
function nonGenericBar(arg: string)
{
    return arg;
}

var y1 = foo1(nonGenericBar);
var y2 = foo2(nonGenericBar);  // Type error"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">nonGenericBar</span><span class="pl-kos">(</span><span class="pl-s1">arg</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span>
<span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-s1">arg</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">var</span> <span class="pl-s1">y1</span> <span class="pl-c1">=</span> <span class="pl-en">foo1</span><span class="pl-kos">(</span><span class="pl-s1">nonGenericBar</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">y2</span> <span class="pl-c1">=</span> <span class="pl-en">foo2</span><span class="pl-kos">(</span><span class="pl-s1">nonGenericBar</span><span class="pl-kos">)</span><span class="pl-kos">;</span>  <span class="pl-c">// Type error</span></pre></div>
<p dir="auto">Of course, <code class="notranslate">genericBar</code> function is useless because constraining a type variable to a primitive type can be replaced by a non generic function like <code class="notranslate">nonGenericBar</code>. However, the behaviour is somewhat unexpected and inconsistent.</p>