In the last line of the next, I want to instantiate a polymorphic function and pass it as an argument.
function id<T> (x:T) { return x; }
console.log ( id<number>(0) )
console.log ( id< (x:number)=>number > (id) (0) )
console.log ( id< (x:number)=>number > (id<number> ) (0) )
I get error TS1005: '(' expected.
So, I can only instantiate a type argument if I also call a function. Really?
Leaving an instance (next line) just works.
For reference, this works in C # (note:) id<int>:
using System;
class P {
static T id<T> (T x) { return x; }
public static void Main (string [] argv) {
Console.WriteLine (id<Func<int,int>> (id<int>) (0));
}
}
Well, I think this is simply not possible in TypeScript. The standard
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#4-expressions says: "TypeScript adds JavaScript expressions with the following constructs: ... Enter arguments in function calls ...", and that, apparently, means "Type arguments only in function calls."