Skip to content

Conversation

@jbaldassari
Copy link
Contributor

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

The current type definition of the agent property of SocketOptions makes it difficult to pass in a custom http agent because it only accepts a string or a boolean:

  /**
   * `http.Agent` to use, defaults to `false` (NodeJS only)
   */
  agent: string | boolean;

In order to pass in a custom agent you need to do something like:

const options = {
  agent: myAgent as unknown as string
};

New behaviour

The type of the agent property now allows includes http.Agent and https.Agent .

I think the correct type should actually be http.Agent | https.Agent | false, but I kept the original string | boolean for backwards compatibility.

Other information (e.g. related issues)

@darrachequesne
Copy link
Member

Hi! Thanks for opening this PR 👍

That would indeed be more correct, but I think this will conflict with users that use the client in a browser environment ("lib": ["dom"] in the tsconfig.json file).

See also: microsoft/TypeScript#29128

@jbaldassari
Copy link
Contributor Author

Ah, I see. Thanks for the explanation. That makes sense.

@jbaldassari jbaldassari closed this Sep 5, 2023
@jbaldassari jbaldassari deleted the fix-agent-type branch September 5, 2023 13:27
darrachequesne added a commit that referenced this pull request Sep 13, 2023
@darrachequesne
Copy link
Member

You're welcome! Added in the source code in 3dcb88c for future reference.

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 this pull request may close these issues.

2 participants