作为函数的泛型类型和作为泛型函数的类型之间存在差异.
您定义的是一个泛型类型,它是一个函数.这意味着我们可以将其分配给具有指定泛型类型的consts:
type FunctionType= (value: TValue) => void; const bar: FunctionType = (value) => { // value is number }
要定义作为泛型函数的类型,我们需要将type参数放在参数列表之前
type FunctionType =(value: TValue) => void; const bar: FunctionType = (value) => { // generic function }