假设某个外部库或打字脚本本身确实声明了函数,如
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
是否可以在不复制粘贴的情况下将此声明用于不同的函数?
假设某个外部库或打字脚本本身确实声明了函数,如
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
是否可以在不复制粘贴的情况下将此声明用于不同的函数?
假设您正在寻找类似下面这样的内容(pseudo code):
declare function fetch(
input: RequestInfo | URL,
init?: RequestInit
): Promise<Response>;
declare function myFetch = fetch;
不,这不可能.但是您可以使用实用程序类型Parameters
和ReturnType
以动态方式复制类型信息,这将为您提供完全相同的签名.
declare function myFetch(
...args: Parameters<typeof fetch>
): ReturnType<typeof fetch>;