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

fix: connector types #1362

Merged
merged 6 commits into from Jun 1, 2022
Merged

fix: connector types #1362

merged 6 commits into from Jun 1, 2022

Conversation

S222em
Copy link
Contributor

@S222em S222em commented Apr 22, 2022

This PR fixes an issue with the type buildConnector.BuildOptions.

The buildConnector.BuildOptions are used for 2 different methods, tls.connect(opts) for https, and net.connect(opt) for all other protocols. TlsOptions does not include all possible options that can be passed to those methods.

  • tls.connect(opt) accepts the type ConnectOptions
  • net.connect(opt) accepts the type NetConnectOpts

types/connector.d.ts Outdated Show resolved Hide resolved
Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We test our types! Can you add an assertion for this using tsd?

@mcollina
Copy link
Member

Also the build is failing

@S222em
Copy link
Contributor Author

S222em commented May 1, 2022

Okay, so @KhafraDev the interface can't actually extend both of the types, it must be type some = 1 | 2. Will it really be a problem? Explained below why it cant be like that:

The type of NetConnectOpts is actually not a interface but a type some = 1 | 2, which could be made into this:

export interface BuildOptions extends ConnectionOptions, TcpNetConnectOpts, IpcNetConnectOpts {
    maxCachedSessions?: number | null;
    socketPath?: string | null;
    timeout?: number | null;
  }

But this gives a TS error that properties of Tcp and Ipc opts can't be both used due to conflicting types.

Then we would get back to this:

export type BuildOptions = (ConnectionOptions | NetConnectOpts) & {
    maxCachedSessions?: number | null;
    socketPath?: string | null;
    timeout?: number | null;
  }

Which could also be:

export type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts ) & {
    maxCachedSessions?: number | null;
    socketPath?: string | null;
    timeout?: number | null;
  }

@S222em
Copy link
Contributor Author

S222em commented May 3, 2022

@mcollina what's your opinion on this? ^

@mcollina
Copy link
Member

mcollina commented May 4, 2022

I think the following look correct:

export type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts ) & {
    maxCachedSessions?: number | null;
    socketPath?: string | null;
    timeout?: number | null;
  }

however I'm not a big expert on TS, so I defer to whatever pleases the tests.

@codecov-commenter
Copy link

codecov-commenter commented May 5, 2022

Codecov Report

Merging #1362 (b3e23d4) into main (f70ac7f) will increase coverage by 0.45%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #1362      +/-   ##
==========================================
+ Coverage   94.24%   94.70%   +0.45%     
==========================================
  Files          45       49       +4     
  Lines        4204     4246      +42     
==========================================
+ Hits         3962     4021      +59     
+ Misses        242      225      -17     
Impacted Files Coverage Δ
lib/fetch/util.js 79.51% <0.00%> (-0.49%) ⬇️
lib/client.js 97.89% <0.00%> (-0.04%) ⬇️
index.js 100.00% <0.00%> (ø)
lib/core/errors.js 100.00% <0.00%> (ø)
lib/proxy-agent.js 100.00% <0.00%> (ø)
lib/api/api-request.js 100.00% <0.00%> (ø)
lib/fetch/constants.js 100.00% <0.00%> (ø)
lib/mock/mock-agent.js 100.00% <0.00%> (ø)
lib/mock/mock-utils.js 100.00% <0.00%> (ø)
lib/mock/mock-interceptor.js 100.00% <0.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f70ac7f...b3e23d4. Read the comment docs.

@mcollina
Copy link
Member

mcollina commented May 5, 2022

Can you add a couple of assertions for this in the types tests?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kibertoad
Copy link
Contributor

@ronag Should this be merged already?

@mcollina
Copy link
Member

@kibertoad is this ok? I'm waiting for somebody to better knowledge of TS than myself.

@kibertoad
Copy link
Contributor

@mcollina This is good to go!

@mcollina mcollina merged commit 966a54f into nodejs:main Jun 1, 2022
KhafraDev added a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* fix: connector types

* fix: add maxCachedSessions, socketPath and timeout back

* Update types/connector.d.ts

Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>

* fix: undo interface

* Add tests

* fix: tests & port should be optional

Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* fix: connector types

* fix: add maxCachedSessions, socketPath and timeout back

* Update types/connector.d.ts

Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>

* fix: undo interface

* Add tests

* fix: tests & port should be optional

Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* fix: connector types

* fix: add maxCachedSessions, socketPath and timeout back

* Update types/connector.d.ts

Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>

* fix: undo interface

* Add tests

* fix: tests & port should be optional

Co-authored-by: Khafra <42794878+KhafraDev@users.noreply.github.com>
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.

None yet

5 participants