js工具库需要index.d.ts 实现.?

写了一个js 工具库,但是 index.d.ts 这块无法得到满意的实现,需要帮助。具体看下方issues
single-promises issues

可在issues 里看到。

阅读 1.4k
2 个回答
interface SingleOptions {
    cache?: number
}

interface SingleFunc<P extends unknown[], T> {
    (...args: P): T extends Promise<unknown> ? T : Promise<T>
    update(opt?: SingleOptions): void
    clear(): void
}

export function singlePromise<P extends unknown[], T>(
    fn: (...args: P) => T,
    opt?: SingleOptions
): SingleFunc<P, T>

给你稍微改了下

declare module 'single-promises' {
  export interface SingleOptions {
      cache?: number;
  }

  type FunctionType = (...args: any) => any;

  export interface SinglePromiseHandle<T extends FunctionType> {
      (...args: Parameters<T>): ReturnType<T> extends Promise<any> ? ReturnType<T> : Promise<ReturnType<T>>;
      clear(): void;
      update(newOpt?: SingleOptions): void;
  }

  export function singlePromise<T extends FunctionType>(fn: T, opt?: SingleOptions): SinglePromiseHandle<T>;

  export const version: string;
}
推荐问题
logo
Microsoft
子站问答
访问
宣传栏