Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent types for agent option #2257

Closed
2 tasks done
sleroq opened this issue Apr 26, 2023 · 0 comments · Fixed by #2258
Closed
2 tasks done

Inconsistent types for agent option #2257

sleroq opened this issue Apr 26, 2023 · 0 comments · Fixed by #2258

Comments

@sleroq
Copy link

sleroq commented Apr 26, 2023

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.
WillianAgostini added a commit to WillianAgostini/got that referenced this issue Apr 30, 2023
WillianAgostini added a commit to WillianAgostini/got that referenced this issue Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant