What is the difference between following generic types:
type FnWithRequiredParam<T> = (t: T) => void
type FnWithParamInferred = <T>(t: T) => void
As far as I understand, the FnWithRequiredParam will always fail if not explicitly given the generic type in any context. Passing the generic (which is enforced), e.g. FnWithRequiredParam<string> will basically turn it into (t: string) => void in all contexts.
However, I can't find the meaning of the FnWithParamInferred. In some contexts <T> gets inferred from the place it's used (such as Array.map), but the following line throws an error:
var f: FnWithParamInferred = (a: number) => { console.log(a) }
saying that number and T are incompatible. In above line, what is actually T? It's never been declared precisely and is being compared to another type. What are the rules for determining what is the generic T defined in function types like <T>(...) => ...?
Seems that, if <T> is defined as a required generic of a class/interface, e.g. an Array<T>, then methods od array can successfully infer T. But if it's outside of a class/interface, type inference doesn't seem to work.