@types/got

  • Version 9.6.12
  • Published
  • 19.8 kB
  • 3 dependencies
  • MIT license

Install

npm i @types/got
yarn add @types/got
pnpm add @types/got

Overview

TypeScript definitions for got

Index

Variables

variable got

const got: got.GotInstance<got.GotFn>;

    Interfaces

    interface AgentOptions

    interface AgentOptions {}

      property http

      http: http.Agent;

        property https

        https: https.Agent;

          interface Cache

          interface Cache {}

            method delete

            delete: (key: string) => any;

              method get

              get: (key: string) => any;

                method set

                set: (key: string, value: any, ttl?: number) => any;

                  interface GotBodyFn

                  interface GotBodyFn<T extends string | null> {}

                    call signature

                    (url: GotUrl): GotPromise<T extends null ? Buffer : string>;

                      call signature

                      (url: GotUrl, options: GotBodyOptions<T>): GotPromise<
                      T extends null ? Buffer : string
                      >;

                        interface GotBodyOptions

                        interface GotBodyOptions<E extends string | null> extends GotOptions<E> {}

                          property body

                          body?: string | Buffer | nodeStream.Readable | undefined;

                            property hooks

                            hooks?:
                            | Hooks<GotBodyOptions<E>, string | Buffer | nodeStream.Readable>
                            | undefined;

                              interface GotEmitter

                              interface GotEmitter {}

                                method addListener

                                addListener: {
                                (event: 'request', listener: (req: http.ClientRequest) => void): this;
                                (event: 'response', listener: (res: http.IncomingMessage) => void): this;
                                (
                                event: 'redirect',
                                listener: (res: http.IncomingMessage, nextOptions: any) => void
                                ): this;
                                (
                                event: 'error',
                                listener: (
                                error: GotError,
                                body?: any,
                                res?: http.IncomingMessage
                                ) => void
                                ): this;
                                (event: 'downloadProgress', listener: (progress: Progress) => void): this;
                                (event: 'uploadProgress', listener: (progress: Progress) => void): this;
                                };

                                  method on

                                  on: {
                                  (event: 'request', listener: (req: http.ClientRequest) => void): this;
                                  (event: 'response', listener: (res: http.IncomingMessage) => void): this;
                                  (
                                  event: 'redirect',
                                  listener: (res: http.IncomingMessage, nextOptions: any) => void
                                  ): this;
                                  (
                                  event: 'error',
                                  listener: (
                                  error: GotError,
                                  body?: any,
                                  res?: http.IncomingMessage
                                  ) => void
                                  ): this;
                                  (event: 'downloadProgress', listener: (progress: Progress) => void): this;
                                  (event: 'uploadProgress', listener: (progress: Progress) => void): this;
                                  };

                                    method once

                                    once: {
                                    (event: 'request', listener: (req: http.ClientRequest) => void): this;
                                    (event: 'response', listener: (res: http.IncomingMessage) => void): this;
                                    (
                                    event: 'redirect',
                                    listener: (res: http.IncomingMessage, nextOptions: any) => void
                                    ): this;
                                    (
                                    event: 'error',
                                    listener: (
                                    error: GotError,
                                    body?: any,
                                    res?: http.IncomingMessage
                                    ) => void
                                    ): this;
                                    (event: 'downloadProgress', listener: (progress: Progress) => void): this;
                                    (event: 'uploadProgress', listener: (progress: Progress) => void): this;
                                    };

                                      method prependListener

                                      prependListener: {
                                      (event: 'request', listener: (req: http.ClientRequest) => void): this;
                                      (event: 'response', listener: (res: http.IncomingMessage) => void): this;
                                      (
                                      event: 'redirect',
                                      listener: (res: http.IncomingMessage, nextOptions: any) => void
                                      ): this;
                                      (
                                      event: 'error',
                                      listener: (
                                      error: GotError,
                                      body?: any,
                                      res?: http.IncomingMessage
                                      ) => void
                                      ): this;
                                      (event: 'downloadProgress', listener: (progress: Progress) => void): this;
                                      (event: 'uploadProgress', listener: (progress: Progress) => void): this;
                                      };

                                        method prependOnceListener

                                        prependOnceListener: {
                                        (event: 'request', listener: (req: http.ClientRequest) => void): this;
                                        (event: 'response', listener: (res: http.IncomingMessage) => void): this;
                                        (
                                        event: 'redirect',
                                        listener: (res: http.IncomingMessage, nextOptions: any) => void
                                        ): this;
                                        (
                                        event: 'error',
                                        listener: (
                                        error: GotError,
                                        body?: any,
                                        res?: http.IncomingMessage
                                        ) => void
                                        ): this;
                                        (event: 'downloadProgress', listener: (progress: Progress) => void): this;
                                        (event: 'uploadProgress', listener: (progress: Progress) => void): this;
                                        };

                                          method removeListener

                                          removeListener: {
                                          (event: 'request', listener: (req: http.ClientRequest) => void): this;
                                          (event: 'response', listener: (res: http.IncomingMessage) => void): this;
                                          (
                                          event: 'redirect',
                                          listener: (res: http.IncomingMessage, nextOptions: any) => void
                                          ): this;
                                          (
                                          event: 'error',
                                          listener: (
                                          error: GotError,
                                          body?: any,
                                          res?: http.IncomingMessage
                                          ) => void
                                          ): this;
                                          (event: 'downloadProgress', listener: (progress: Progress) => void): this;
                                          (event: 'uploadProgress', listener: (progress: Progress) => void): this;
                                          };

                                            interface GotExtend

                                            interface GotExtend {}

                                              call signature

                                              (options: GotJSONOptions): GotInstance<GotJSONFn>;

                                                call signature

                                                (options: GotFormOptions<string>): GotInstance<GotFormFn<string>>;

                                                  call signature

                                                  (options: GotFormOptions<null>): GotInstance<GotFormFn<null>>;

                                                    call signature

                                                    (options: GotBodyOptions<string>): GotInstance<GotBodyFn<string>>;

                                                      call signature

                                                      (options: GotBodyOptions<null>): GotInstance<GotBodyFn<null>>;

                                                        interface GotFn

                                                        interface GotFn {}

                                                          call signature

                                                          (url: GotUrl): GotPromise<string>;

                                                            call signature

                                                            (url: GotUrl, options: GotJSONOptions): GotPromise<any>;

                                                              call signature

                                                              (url: GotUrl, options: GotFormOptions<string>): GotPromise<string>;

                                                                call signature

                                                                (url: GotUrl, options: GotFormOptions<null>): GotPromise<Buffer>;

                                                                  call signature

                                                                  (url: GotUrl, options: GotBodyOptions<string>): GotPromise<string>;

                                                                    call signature

                                                                    (url: GotUrl, options: GotBodyOptions<null>): GotPromise<Buffer>;

                                                                      interface GotFormFn

                                                                      interface GotFormFn<T extends string | null> {}

                                                                        call signature

                                                                        (url: GotUrl): GotPromise<T extends null ? Buffer : string>;

                                                                          call signature

                                                                          (url: GotUrl, options: Partial<GotFormOptions<T>>): GotPromise<
                                                                          T extends null ? Buffer : string
                                                                          >;

                                                                            interface GotFormOptions

                                                                            interface GotFormOptions<E extends string | null> extends GotOptions<E> {}

                                                                              property body

                                                                              body?: Record<string, any> | undefined;

                                                                                property form

                                                                                form: true;

                                                                                  property hooks

                                                                                  hooks?: Hooks<GotFormOptions<E>, Record<string, any>> | undefined;

                                                                                    property json

                                                                                    json?: boolean | undefined;

                                                                                      interface GotJSONFn

                                                                                      interface GotJSONFn {}

                                                                                        call signature

                                                                                        (url: GotUrl): GotPromise<any>;

                                                                                          call signature

                                                                                          (url: GotUrl, options: Partial<GotJSONOptions>): GotPromise<any>;

                                                                                            interface GotJSONOptions

                                                                                            interface GotJSONOptions extends GotOptions<string | null> {}

                                                                                              property body

                                                                                              body?: object | undefined;

                                                                                                property form

                                                                                                form?: boolean | undefined;

                                                                                                  property hooks

                                                                                                  hooks?: Hooks<GotJSONOptions, object> | undefined;

                                                                                                    property json

                                                                                                    json: true;

                                                                                                      interface GotOptions

                                                                                                      interface GotOptions<E extends string | null> extends InternalRequestOptions {}

                                                                                                        property agent

                                                                                                        agent?: http.Agent | boolean | AgentOptions | undefined;

                                                                                                          property baseUrl

                                                                                                          baseUrl?: string | undefined;

                                                                                                            property cache

                                                                                                            cache?: Cache | undefined;

                                                                                                              property cookieJar

                                                                                                              cookieJar?: CookieJar | undefined;

                                                                                                                property decompress

                                                                                                                decompress?: boolean | undefined;

                                                                                                                  property encoding

                                                                                                                  encoding?: E | undefined;

                                                                                                                    property followRedirect

                                                                                                                    followRedirect?: boolean | undefined;

                                                                                                                      property query

                                                                                                                      query?: Record<string, any> | URLSearchParams | string | undefined;

                                                                                                                        property request

                                                                                                                        request?: RequestFunction | undefined;

                                                                                                                          property retry

                                                                                                                          retry?: number | RetryOptions | undefined;

                                                                                                                            property throwHttpErrors

                                                                                                                            throwHttpErrors?: boolean | undefined;

                                                                                                                              property timeout

                                                                                                                              timeout?: number | TimeoutOptions | undefined;

                                                                                                                                property useElectronNet

                                                                                                                                useElectronNet?: boolean | undefined;

                                                                                                                                  interface GotTimings

                                                                                                                                  interface GotTimings {}

                                                                                                                                    property connect

                                                                                                                                    connect: number;

                                                                                                                                      property end

                                                                                                                                      end: number;

                                                                                                                                        property error

                                                                                                                                        error: number;

                                                                                                                                          property lookup

                                                                                                                                          lookup: number;

                                                                                                                                            property phases

                                                                                                                                            phases: GotTimingsPhases;

                                                                                                                                              property response

                                                                                                                                              response: number;

                                                                                                                                                property socket

                                                                                                                                                socket: number;

                                                                                                                                                  property start

                                                                                                                                                  start: number;

                                                                                                                                                    property upload

                                                                                                                                                    upload: number;

                                                                                                                                                      interface GotTimingsPhases

                                                                                                                                                      interface GotTimingsPhases {}

                                                                                                                                                        property dns

                                                                                                                                                        dns: number;

                                                                                                                                                          property download

                                                                                                                                                          download: number;

                                                                                                                                                            property firstByte

                                                                                                                                                            firstByte: number;

                                                                                                                                                              property request

                                                                                                                                                              request: number;

                                                                                                                                                                property tcp

                                                                                                                                                                tcp: number;

                                                                                                                                                                  property total

                                                                                                                                                                  total: number;

                                                                                                                                                                    property wait

                                                                                                                                                                    wait: number;

                                                                                                                                                                      interface Hooks

                                                                                                                                                                      interface Hooks<Options, Body extends Buffer | string | object> {}
                                                                                                                                                                      • Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.

                                                                                                                                                                        See Also

                                                                                                                                                                        • https://github.com/sindresorhus/got#hooks Options Request options. Body Response body type.

                                                                                                                                                                      property afterResponse

                                                                                                                                                                      afterResponse?: Array<AfterResponseHook<Options, Body>> | undefined;

                                                                                                                                                                        property beforeError

                                                                                                                                                                        beforeError?: BeforeErrorHook[] | undefined;

                                                                                                                                                                          property beforeRedirect

                                                                                                                                                                          beforeRedirect?: Array<BeforeRedirectHook<Options>> | undefined;

                                                                                                                                                                            property beforeRequest

                                                                                                                                                                            beforeRequest?: Array<BeforeRequestHook<Options>> | undefined;

                                                                                                                                                                              property beforeRetry

                                                                                                                                                                              beforeRetry?: Array<BeforeRetryHook<Options>> | undefined;

                                                                                                                                                                                property init

                                                                                                                                                                                init?: Array<InitHook<Options>> | undefined;

                                                                                                                                                                                  interface Progress

                                                                                                                                                                                  interface Progress {}

                                                                                                                                                                                    property percent

                                                                                                                                                                                    percent: number;

                                                                                                                                                                                      property total

                                                                                                                                                                                      total: number | null;

                                                                                                                                                                                        property transferred

                                                                                                                                                                                        transferred: number;

                                                                                                                                                                                          interface Response

                                                                                                                                                                                          interface Response<B extends Buffer | string | object>
                                                                                                                                                                                          extends http.IncomingMessage {}

                                                                                                                                                                                            property body

                                                                                                                                                                                            body: B;

                                                                                                                                                                                              property fromCache

                                                                                                                                                                                              fromCache: boolean;

                                                                                                                                                                                                property redirectUrls

                                                                                                                                                                                                redirectUrls?: string[] | undefined;

                                                                                                                                                                                                  property requestUrl

                                                                                                                                                                                                  requestUrl: string;

                                                                                                                                                                                                    property retryCount

                                                                                                                                                                                                    retryCount: number;

                                                                                                                                                                                                      property statusCode

                                                                                                                                                                                                      statusCode: number;

                                                                                                                                                                                                        property statusMessage

                                                                                                                                                                                                        statusMessage: string;

                                                                                                                                                                                                          property timings

                                                                                                                                                                                                          timings: GotTimings;

                                                                                                                                                                                                            property url

                                                                                                                                                                                                            url: string;

                                                                                                                                                                                                              interface RetryOptions

                                                                                                                                                                                                              interface RetryOptions {}

                                                                                                                                                                                                                property errorCodes

                                                                                                                                                                                                                errorCodes?: string[] | undefined;
                                                                                                                                                                                                                • Allowed error codes.

                                                                                                                                                                                                                property maxRetryAfter

                                                                                                                                                                                                                maxRetryAfter?: number | undefined;

                                                                                                                                                                                                                  property methods

                                                                                                                                                                                                                  methods?:
                                                                                                                                                                                                                  | Array<'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE'>
                                                                                                                                                                                                                  | undefined;

                                                                                                                                                                                                                    property retries

                                                                                                                                                                                                                    retries?: number | RetryFunction | undefined;

                                                                                                                                                                                                                      property statusCodes

                                                                                                                                                                                                                      statusCodes?: Array<408 | 413 | 429 | 500 | 502 | 503 | 504> | undefined;

                                                                                                                                                                                                                        interface TimeoutOptions

                                                                                                                                                                                                                        interface TimeoutOptions {}
                                                                                                                                                                                                                        • Contains properties to constrain the duration of each phase of the request lifecycle.

                                                                                                                                                                                                                          See Also

                                                                                                                                                                                                                          • https://github.com/sindresorhus/got#timeout

                                                                                                                                                                                                                        property connect

                                                                                                                                                                                                                        connect?: number | undefined;
                                                                                                                                                                                                                        • Starts when lookup completes (or when the socket is assigned if lookup does not apply to the request) and ends when the socket is connected.

                                                                                                                                                                                                                        property lookup

                                                                                                                                                                                                                        lookup?: number | undefined;
                                                                                                                                                                                                                        • Starts when a socket is assigned and ends when the hostname has been resolved. Does not apply when using a Unix domain socket.

                                                                                                                                                                                                                        property request

                                                                                                                                                                                                                        request?: number | undefined;
                                                                                                                                                                                                                        • Starts when the request is initiated and ends when the response's end event fires.

                                                                                                                                                                                                                        property response

                                                                                                                                                                                                                        response?: number | undefined;
                                                                                                                                                                                                                        • Starts when the request has been written to the socket and ends when the response headers are received.

                                                                                                                                                                                                                        property secureConnect

                                                                                                                                                                                                                        secureConnect?: number | undefined;
                                                                                                                                                                                                                        • Starts when connect completes and ends when the handshaking process completes (HTTPS only).

                                                                                                                                                                                                                        property send

                                                                                                                                                                                                                        send?: number | undefined;
                                                                                                                                                                                                                        • Starts when the socket is connected and ends with the request has been written to the socket.

                                                                                                                                                                                                                        property socket

                                                                                                                                                                                                                        socket?: number | undefined;
                                                                                                                                                                                                                        • Starts when the socket is connected. See [request.setTimeout](https://nodejs.org/api/http.html#http_request_settimeout_timeout_callback).

                                                                                                                                                                                                                        Type Aliases

                                                                                                                                                                                                                        type AfterResponseHook

                                                                                                                                                                                                                        type AfterResponseHook<Options, Body extends Buffer | string | object> = (
                                                                                                                                                                                                                        response: Response<Body>,
                                                                                                                                                                                                                        retryWithMergedOptions: (updateOptions: Options) => GotPromise<Body>
                                                                                                                                                                                                                        ) => Response<Body> | Promise<Response<Body>>;
                                                                                                                                                                                                                        • Parameter response

                                                                                                                                                                                                                          Response object.

                                                                                                                                                                                                                          Parameter retryWithMergedOptions

                                                                                                                                                                                                                          Retries request with the updated options.

                                                                                                                                                                                                                        type BeforeErrorHook

                                                                                                                                                                                                                        type BeforeErrorHook = (error: GotError) => Error | Promise<Error>;

                                                                                                                                                                                                                          type BeforeRedirectHook

                                                                                                                                                                                                                          type BeforeRedirectHook<Options> = (options: Options) => any;
                                                                                                                                                                                                                          • Parameter options

                                                                                                                                                                                                                            Normalized request options.

                                                                                                                                                                                                                          type BeforeRequestHook

                                                                                                                                                                                                                          type BeforeRequestHook<Options> = (options: Options) => any;
                                                                                                                                                                                                                          • Parameter options

                                                                                                                                                                                                                            Normalized request options.

                                                                                                                                                                                                                          type BeforeRetryHook

                                                                                                                                                                                                                          type BeforeRetryHook<Options> = (
                                                                                                                                                                                                                          options: Options,
                                                                                                                                                                                                                          error: GotError,
                                                                                                                                                                                                                          retryCount: number
                                                                                                                                                                                                                          ) => any;
                                                                                                                                                                                                                          • Parameter options

                                                                                                                                                                                                                            Normalized request options.

                                                                                                                                                                                                                            Parameter error

                                                                                                                                                                                                                            Request error.

                                                                                                                                                                                                                            Parameter retryCount

                                                                                                                                                                                                                            Number of retry.

                                                                                                                                                                                                                          type GotError

                                                                                                                                                                                                                          type GotError =
                                                                                                                                                                                                                          | RequestError
                                                                                                                                                                                                                          | ReadError
                                                                                                                                                                                                                          | ParseError
                                                                                                                                                                                                                          | HTTPError
                                                                                                                                                                                                                          | MaxRedirectsError
                                                                                                                                                                                                                          | UnsupportedProtocolError
                                                                                                                                                                                                                          | CancelError
                                                                                                                                                                                                                          | TimeoutError;

                                                                                                                                                                                                                            type GotInstance

                                                                                                                                                                                                                            type GotInstance<T = GotFn> = T &
                                                                                                                                                                                                                            Record<'get' | 'post' | 'put' | 'patch' | 'head' | 'delete', T> & {
                                                                                                                                                                                                                            stream: GotStreamFn &
                                                                                                                                                                                                                            Record<
                                                                                                                                                                                                                            'get' | 'post' | 'put' | 'patch' | 'head' | 'delete',
                                                                                                                                                                                                                            GotStreamFn
                                                                                                                                                                                                                            >;
                                                                                                                                                                                                                            extend: GotExtend;
                                                                                                                                                                                                                            RequestError: typeof RequestError;
                                                                                                                                                                                                                            ReadError: typeof ReadError;
                                                                                                                                                                                                                            ParseError: typeof ParseError;
                                                                                                                                                                                                                            HTTPError: typeof HTTPError;
                                                                                                                                                                                                                            MaxRedirectsError: typeof MaxRedirectsError;
                                                                                                                                                                                                                            UnsupportedProtocolError: typeof UnsupportedProtocolError;
                                                                                                                                                                                                                            CancelError: typeof CancelError;
                                                                                                                                                                                                                            TimeoutError: typeof TimeoutError;
                                                                                                                                                                                                                            };

                                                                                                                                                                                                                              type GotPromise

                                                                                                                                                                                                                              type GotPromise<B extends Buffer | string | object> = Promise<Response<B>> & {
                                                                                                                                                                                                                              cancel(): void;
                                                                                                                                                                                                                              };

                                                                                                                                                                                                                                type GotStreamFn

                                                                                                                                                                                                                                type GotStreamFn = (
                                                                                                                                                                                                                                url: GotUrl,
                                                                                                                                                                                                                                options?: GotOptions<string | null>
                                                                                                                                                                                                                                ) => GotEmitter & nodeStream.Duplex;

                                                                                                                                                                                                                                  type GotUrl

                                                                                                                                                                                                                                  type GotUrl = string | https.RequestOptions | Url | URL;

                                                                                                                                                                                                                                    type InitHook

                                                                                                                                                                                                                                    type InitHook<Options> = (options: Options) => void;
                                                                                                                                                                                                                                    • Parameter options

                                                                                                                                                                                                                                      Unnormalized request options.

                                                                                                                                                                                                                                    type RequestFunction

                                                                                                                                                                                                                                    type RequestFunction = typeof https.request;

                                                                                                                                                                                                                                      type RetryFunction

                                                                                                                                                                                                                                      type RetryFunction = (retry: number, error: any) => number;

                                                                                                                                                                                                                                        Package Files (1)

                                                                                                                                                                                                                                        Dependencies (3)

                                                                                                                                                                                                                                        Dev Dependencies (0)

                                                                                                                                                                                                                                        No dev dependencies.

                                                                                                                                                                                                                                        Peer Dependencies (0)

                                                                                                                                                                                                                                        No peer dependencies.

                                                                                                                                                                                                                                        Badge

                                                                                                                                                                                                                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/got.

                                                                                                                                                                                                                                        • Markdown
                                                                                                                                                                                                                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/got)
                                                                                                                                                                                                                                        • HTML
                                                                                                                                                                                                                                          <a href="https://www.jsdocs.io/package/@types/got"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>