请参见代码:
interface Bar<T> {
<B_RETURN>(
a: (aParam: B_RETURN) => any,
b: (bParam: T) => B_RETURN // B_RETURN is supposed to be inferred from here
): any
}
declare const bar: Bar<any>
bar((aParam) => 1, () => 'abc') // OK! `aParam` is `string`
bar((aParam) => 1, (bParam) => 'abc') // `aParam` is `{}`. Why?
bar((aParam) => 1, (bParam: any) => 'abc') // `aParam` is `string`. Again, why?
let arg2 = (bParam) => 'abc' ; bar((aParam ) => 1, arg2) // `aParam` is `string`. Again, why?
aParam
应该是
string
在四个例子中的每一个,但是由于某种原因
{}
而不是
一串
在第二个例子中。有人能解释为什么会这样吗?
Playground