Skip to content

Inconsistent types for agent option #2257

@sleroq

Description

@sleroq

Describe the bug

  • Node.js version: 18.15.0
  • Typescript version: 5.0.4
  • OS & version: NixOS 22.11.3889.f5364316e31 (Raccoon) x86_64

I noticed that the type definition for the agent option allows undefined as a valid value, but when I pass undefined at runtime, I get an error saying that agent value is expected to be an object.

Actual behavior

➜  testing-got tsc && node dist/index.js
node:internal/process/esm_loader:97
    internalBinding('errors').triggerUncaughtException(
                              ^

RequestError: Expected value which is `plain object`, received value of type `undefined`.
    at Request._destroy (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/core/index.js:481:21)
    at _destroy (node:internal/streams/destroy:109:10)
    at Request.destroy (node:internal/streams/destroy:71:5)
    at Request.flush (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/core/index.js:240:22)
    at lastHandler (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/create.js:37:26)
    at iterateHandlers (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/create.js:49:28)
    at got (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/create.js:69:16)
    at file:///home/sleroq/develop/other/testing-got/dist/index.js:2:7
    at assertType (file:///home/sleroq/develop/other/testing-got/node_modules/@sindresorhus/is/dist/index.js:305:15)
    at Object.plainObject (file:///home/sleroq/develop/other/testing-got/node_modules/@sindresorhus/is/dist/index.js:377:29)
    at set agent [as agent] (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/core/options.js:461:16)
    at Options.merge (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/core/options.js:411:27)
    at new Options (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/core/options.js:355:26)
    at new Request (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/core/index.js:224:28)
    at got (file:///home/sleroq/develop/other/testing-got/node_modules/got/dist/source/create.js:31:25)
    at file:///home/sleroq/develop/other/testing-got/dist/index.js:2:7
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {

Expected behavior

I expected the code to run without any errors and print the response body from example.com.

Code to reproduce

import got from 'got';

await got('https://example.com', {
    agent: undefined,
})

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions