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

1.9.0 Deno.connect() types the connection to Conn<NetAddr> making code incompatible #10200

Closed
aricart opened this issue Apr 15, 2021 · 7 comments · Fixed by #10205
Closed

1.9.0 Deno.connect() types the connection to Conn<NetAddr> making code incompatible #10200

aricart opened this issue Apr 15, 2021 · 7 comments · Fixed by #10205

Comments

@aricart
Copy link
Contributor

aricart commented Apr 15, 2021

Previous versions of deno had non-generic Conn. This breaks libraries that work perfectly with any version of deno.

@aricart
Copy link
Contributor Author

aricart commented Apr 15, 2021

Obviously, the backward and forwards solution is // @ts-ignore: Deno added generics to Conn but maybe there's something that can be done that is more elegant.

@bartlomieju
Copy link
Member

@aricart could you provide example of code that got broken?

@aricart
Copy link
Contributor Author

aricart commented Apr 15, 2021

Sorry - Deno.startTls changed signature, so code as below, will fail to compile in 1.9.0

let conn: Deno.Conn;
const hostname = "connect.ngs.global";

conn = await Deno.connect({hostname: hostname, port: 4222});
// other stuff happening here after detecting the server supports TLS
....
conn = await Deno.startTls(
  conn,
  { hostname: hostname },
);

console.log("connected");

@aricart
Copy link
Contributor Author

aricart commented Apr 15, 2021

error: TS2345 [ERROR]: Argument of type 'Conn<Addr>' is not assignable to parameter of type 'Conn<NetAddr>'.
  Type 'Addr' is not assignable to type 'NetAddr'.
    Type 'UnixAddr' is missing the following properties from type 'NetAddr': hostname, port
  conn,

Pacifying it on 1.9.0 by specifying the Conn<NetAddr> will equally make the code incompatible on older versions.

@kitsonk
Copy link
Contributor

kitsonk commented Apr 15, 2021

Doing this:

const hostname = "connect.ngs.global";

let conn = await Deno.connect({ hostname: hostname, port: 4222 });
// other stuff happening here after detecting the server supports TLS

conn = await Deno.startTls(
  conn,
  { hostname: hostname },
);

console.log("connected");

Fixes it under Deno 1.9. Is that not acceptable?

@aricart
Copy link
Contributor Author

aricart commented Apr 16, 2021

When declared as a field in a class, as it is used by me, it doesn't. The type is declared and the generics breaks it for 1.9.0, and if I can get it it is broken for previous versions...

@kt3k
Copy link
Member

kt3k commented Sep 7, 2021

I think #10012 wasn't breaking with the above example if we had set default of type parameter to NetAddr like:

interface Conn<Address extends Addr = NetAddr>

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.

4 participants