proxy-agents icon indicating copy to clipboard operation
proxy-agents copied to clipboard

typescript error with latest @types/node for example, 20.19.2

Open jeremymeng opened this issue 4 months ago • 7 comments

Seems related to https://github.com/DefinitelyTyped/DefinitelyTyped/commit/239534ac5225c56966e7df1b83aeba21a29f6349#diff-57e7757e84d63cfecb505f51e2bceaa12ecc23024bf9eabeb37572f4c51930a6R1647

We are now seeing errors:

error    2416   Property 'getName' in type 'Agent' is not assignable to the same property in base type 'Agent'.
                                    Type '(options: AgentConnectOpts) => string' is not assignable to type '(options?: AgentGetNameOptions) => string'.
                                      Types of parameters 'options' and 'options' are incompatible.
                                        Type 'AgentGetNameOptions' is not assignable to type 'AgentConnectOpts'.
                                          Property 'secureEndpoint' is missing in type 'AgentGetNameOptions' but required in type 'HttpConnectOpts'. (lsp)

jeremymeng avatar Jun 30 '25 18:06 jeremymeng

or maybe @types/node shouldn't have breaking changes?

jeremymeng avatar Jun 30 '25 18:06 jeremymeng

I have the same issue

node_modules/agent-base/dist/index.d.ts:33:5 - error TS2416: Property 'getName' in type 'Agent' is not assignable to the same property in base type 'Agent'. Type '(options: AgentConnectOpts) => string' is not assignable to type '(options?: AgentGetNameOptions | undefined) => string'. Types of parameters 'options' and 'options' are incompatible. Type 'AgentGetNameOptions | undefined' is not assignable to type 'AgentConnectOpts'. Type 'undefined' is not assignable to type 'AgentConnectOpts'.

33 getName(options: AgentConnectOpts): string; ~~~~~~~

PantaFlutter avatar Jul 02 '25 13:07 PantaFlutter

I bump @types/node version and have the same error

Image

PantaFlutter avatar Jul 02 '25 13:07 PantaFlutter

Perhaps the agent-base (and this repository) shouldn't use Node.js 14 types, as that version is EOL, and use at least v20 instead, keeping it up to date.

https://github.com/TooTallNate/proxy-agents/issues/376

AndKiel avatar Jul 09 '25 08:07 AndKiel

For anyone uses Node 22 : I had the same issue. Seems like the signature of the getName method of the agent-base has been the same since forever. The types/node forces a specific signature of this method since the v22.12.0. I had to downgrade to the version 22.10.10, and it works. Waiting for agent-base to update so it has the same parameter types.

For people using Node 20, try to find a version of types/node that doesn't implement the getName method in its interface (could be found in http.d.ts file)

MW1-Skan avatar Jul 10 '25 08:07 MW1-Skan

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/73194 appears to have fixed the issues (that is, @types/node modified things to work with this again).

mook-as avatar Jul 11 '25 17:07 mook-as

I just checked with nodejs 20.19.4 and @types/node 20.19.11, unfortunately https://github.com/TooTallNate/proxy-agents/blob/b923f5363875d8fd56477094d5ffc562840a4b76/packages/agent-base/src/index.ts#L130-L133 breaks again !?!

kapouer avatar Aug 21 '25 13:08 kapouer