declare var f: {
<U>(x: U): U,
};
declare function pipe<T>(arg: T, dit: (arg: T) => T): T; // welkom in F#!
declare function apply<V>(dit: (arg: V) => V, arg: V): V;
let n = pipe(12, f);
let m = apply(f, 12);
n: number as desired but m: {}. It looks like, during the second pass of type parameter inference for apply, the call signature is inferred from dit's argument before it is inferred from arg. Since f is itself generic, the default is {}. @ahejlsberg, is this intended behaviour? It seems like a bug to me.
Also I am not sure why getSingleCallSignature special-cases single-call-signature-only objects. You get yet a different result if you have an extra property on f:
declare var f: {
<U>(x: U): U,
hunch(x: number): number
};
...
let n = pipe(12, f)
let m = apply(f, 12)
Now both n: any and m: any because getSingleCallSignature doesn't return a signature, so instantiateTypeWithSingleGenericCallSignature doesn't do its instantiation at all.
n: numberas desired butm: {}. It looks like, during the second pass of type parameter inference forapply, the call signature is inferred fromdit's argument before it is inferred fromarg. Sincefis itself generic, the default is{}. @ahejlsberg, is this intended behaviour? It seems like a bug to me.Also I am not sure why
getSingleCallSignaturespecial-cases single-call-signature-only objects. You get yet a different result if you have an extra property onf:Now both
n: anyandm: anybecause getSingleCallSignature doesn't return a signature, soinstantiateTypeWithSingleGenericCallSignaturedoesn't do its instantiation at all.