Typescript 通过函数类型的索引获取参数

Typescript 通过函数类型的索引获取参数,typescript,Typescript,我有一个函数类型: export interface NativeMethods { measureLayout( relativeToNativeComponentRef: HostComponent<unknown> | number, onSuccess: MeasureLayoutOnSuccessCallback, onFail: () => void /* currently unused */, ): vo

我有一个函数类型:

export interface NativeMethods {

measureLayout(
        relativeToNativeComponentRef: HostComponent<unknown> | number,
        onSuccess: MeasureLayoutOnSuccessCallback,
        onFail: () => void /* currently unused */,
    ): void;

}
导出接口本地方法{
测量(
relativeToNativeComponentRef:HostComponent |编号,
onSuccess:MeasureLayoutOnSuccessCallback,
onFail:()=>void/*当前未使用的*/,,
):无效;
}
这实际上是在一个库中。我想获得每个参数的类型,如以下伪代码:

类型Param1=参数[0]

但是它不起作用,有什么想法吗?

您可以使用索引访问类型()执行此操作,如下所示:

type Param1 = Parameters<NativeMethods['measureLayout']>[0];
type Param1=参数[0];

您可以使用索引访问类型()执行此操作,如下所示:

type Param1 = Parameters<NativeMethods['measureLayout']>[0];
type Param1=参数[0];

哦,哇,太微妙了!非常感谢。哦,哇,太微妙了!非常感谢。