Skip to content

Can't set agents when agent type is false #2360

@shellvon

Description

@shellvon

Describe the bug

  • Node.js version:
  • OS & version:

Currently , the agent type is:

export type Agents = {
http?: HttpAgent | false;
https?: HttpsAgent | false;
http2?: unknown | false;
};

as you can see, false is a valid type, but when i set agent to false, it throws an error!

got/source/core/options.ts

Lines 1136 to 1146 in 23b2f26

set agent(value: Agents) {
assert.plainObject(value);
// eslint-disable-next-line guard-for-in
for (const key in value) {
if (!(key in this._internals.agent)) {
throw new TypeError(`Unexpected agent option: ${key}`);
}
// @ts-expect-error - No idea why `value[key]` doesn't work here.
assert.any([is.object, is.undefined], value[key]);

Actual behavior

Can't set agent when agent type is false

Expected behavior

change type declare (maybe remove false type?) or just make false as a valid type when set agent, I think the latter would be better.

Code to reproduce

// just set agent to false.

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