rock-req icon indicating copy to clipboard operation
rock-req copied to clipboard

Feat: Add typescript definitions on npm

Open ShivamJoker opened this issue 2 years ago • 1 comments

Hey thanks for the great work you've put out here. It would be great to get built in types.

ShivamJoker avatar Aug 04 '23 19:08 ShivamJoker

Hello,

Oh yes, it was on my roadmap. I need some time to do it. Feel free to open a pull request, even if it is not perfect. It will help me a lot.

Here were my initial notes on it:

declare module 'rock-req' {
  import { Agent } from 'http';
  import { RequestOptions as HttpRequestOptions } from 'https';
  import { Writable, Readable } from 'stream';

  export interface RequestOptions extends HttpRequestOptions {
    maxRedirects?: number;
    maxRetry?: number;
    retryDelay?: number;
    keepAliveDuration?: number;
    retryOnCode?: number[];
    retryOnError?: string[];
    beforeRequest?: (options: RequestOptions) => RequestOptions;
    json?: boolean;
    form?: any;
    output?: (options: RequestOptions, response: Response) => Writable;
    remainingRetry?: number;
    remainingRedirects?: number;
    body?: string | Buffer | Readable;
    prevError?: Error;
    prevStatusCode?: number;
  }

  export function rock(opts: RequestOptions | string, directBody?: any, cb?: (err: Error | null, response?: Response, data?: any) => void): any;
  export function extend(defaultOptions?: RequestOptions): typeof rock;

  export interface Rock {
    get: typeof rock;
    post: typeof rock;
  }
}

dgrelaud avatar Jan 08 '24 16:01 dgrelaud