There is a difference between a generic type that happens to be a function and a type that is a generic function.
(碰巧是函数的泛型和泛型函数之间有区别。)
What you defined there is a generic type that is a function.
(您定义的是一个泛型类型,即一个函数。)
This means that we can assign this to consts that have the generic types specified: (这意味着我们可以将其分配给具有指定泛型类型的const:)
type FunctionType<TValue> = (value: TValue) => void;
const bar: FunctionType<number> = (value) => { // value is number
}
To define a type that is a generic function we need to put the type parameter before the arguments list
(要定义一个泛型类型,我们需要将类型参数放在参数列表之前)
type FunctionType = <TValue>(value: TValue) => void;
const bar: FunctionType = <TValue>(value) => { // generic function
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…