背景
我遇到了一个问题,无法从一个重载的函数中获取特定参数。例如:
// someLib.d.ts
type Component<T> = {};
type A = {};
type B = {};
type C = {};
type Opts = {};
type ModernOpts = {};
export declare function mount(component: A, options: Opts): Component<A>;
export declare function mount(component: B, options: Opts): Component<B>;
export declare function mount(component: C, options: ModernOpts): Component<C>;
问题是,但我在另一个文件上这样做时:
import { mount } from 'someLib';
type specificMountParams = Parameters<typeof mount>;
我得到的参数是[C,ModernOpts]
,似乎没有办法获取[A,Opts]
或[B,Opts]
参数。
问题
是否有任何方法可以从重载函数中检索特定参数?(因此我可以获取[A,Opts]
参数)
限制和信息
这些类型(A,B,Opts)
未由库导出,我需要创建一个函数来执行类似操作所需的此类类型。