Typescript 如何获取整个函数的类型,而不仅仅是参数或返回类型

Typescript 如何获取整个函数的类型,而不仅仅是参数或返回类型,typescript,Typescript,我正在寻找一种方法来获得给定函数的整个类型 例如: const AddOne = (a) => a + 1 type Example = FunctionType<typeof AddOne> const AddOne=(a)=>a+1 类型示例=函数类型 在这里: export type FunctionType<T extends (...args: any) => any> = (...a: Parameters<T>) => Re

我正在寻找一种方法来获得给定函数的整个类型

例如:

const AddOne = (a) => a + 1

type Example = FunctionType<typeof AddOne>
const AddOne=(a)=>a+1
类型示例=函数类型
在这里:

export type FunctionType<T extends (...args: any) => any> = (...a: Parameters<T>) => ReturnType<T>
导出类型FunctionType any>=(…a:参数)=>返回类型

为什么不干脆
type Example=typeof AddOne
。你的类型只是作为函数签名的标识。是的,我不理解这个用例。如果需要“整个类型”,则需要
type FunctionType=T
。如果您想将其限制为函数类型,我想您可以使用
typefunctiontypeany>=T
,但它仍然只是标识类型函数。