node, ws: address() method on Server and related classes can return a string#25597
Conversation
|
@thw0rted Thank you for submitting this PR! 🔔 @hertzg @parambirs @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk @wwwy3y3 @DeividasBakanas @kjin @alvis @OliverJAsh @eps1lon @Hannes-Magnusson-CK @jkomyno @ajafff @hoo29 @n-e @markisme @Taisiias @dex4er @MugeSo @nickmorton @loyd @elithrar @mlamp @TitaneBoy @orblazer - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@thw0rted The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
Whoever comes to review this, can you take a look at that Travis build? It looks like some kind of internal error, not related to the PR. |
|
Node part looks correct. |
|
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
Amending commit message to re-trigger Travis build.
… string (DefinitelyTyped#25597) * node: ClearTextStream hasn't existed for 3 years * node: move AddressInfo to net module; address() can return string * ws: Server.address() can return string (same as net.Server.address etc) * Fix some tests that assumed Server.address returns AddressInfo Amending commit message to re-trigger Travis build.
|
Hey @thw0rted @Flarna just so you're aware, this type of change breaks compatibility with older node type definitions. Because you updated This creates a breaking situation for anyone using the I have opened a PR to fix this issue #26196 in |
|
I thought the way NPM was supposed to handle this was that the top level project can rely on Alternately: in this specific case, I believe the problem is that an anonymous interface was given a name and exported, then used in the packages you listed. The interface has existed and been used in more or less all versions of |
|
NPM does not resolve it that way in this case, no. The dependencies for You could also go back and make the interface available in older versions of node, but to do it the right way you'd want to find out when that interface was introduced and go all the way back to that version. After reading through your changes and the |
|
I'm still kind of new at this, but I think the problem is one of conventions in the vanilla-JS world. Before TS came along, JS didn't have the vocabulary to discuss interfaces -- at least, not something universal and consistent. So you had years of docs saying "this function returns an object with the following structure..." but never gave a name to that structure. Since the canonical docs that were (probably) used to generate the initial DT typings don't explicitly label an interface (and why would they?), it's up to individual DT authors to decide if and how to name interfaces -- and once that decision is made, it has ramifications for all versions in the future. Now, with the benefit of hindsight (!), I can say that the decision to not name the interface used in these functions -- or worse yet, to name it in some places and not others -- was a mistake. But retroactively fixing that mistake, going to a better design, causes the breakage you're seeing. Like I said, I'm new here, so I don't know how the community wants to see these problems solved. I think the structure-I-call-AddressInfo has been in Node for as far back as I can still find docs, but whose code am I going to break if I reach back into older versions and label it? |
|
No worries, I can't really say I'm an expert either but I've got some experience under my belt with tracking down these type definition issues since we deal with quite a lot of them at my work. Regarding your concerns about labeling the interface, it's not really the giving it a name that breaks it, it's that you added that name in a version of the node types that not everyone can use, and then imported it into the dependent packages. The name itself in TS isn't taken into account when it comes to type compatibility. Your |
|
I'm quite sure that In this case it would be most likely best to update also older node versions. But as this change is breaking for quite some users - pipe/domain socket servers are use rare and even then users know what they use but after the change a cast/type check is needed it may result in complains. |
Use a meaningful title for the pull request. Include the name of the package modified.
Test the change in your own code. (Compile and run.)
Add or edit tests to reflect the change. (Run with
npm test.)Follow the advice from the readme.
Avoid common mistakes.
Run
npm run lint package-name(ortscif notslint.jsonis present).Provide a URL to documentation or source code which provides context for the suggested changes:
Increase the version number in the header if appropriate. N/A
If you are making substantial changes, consider adding a
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }. N/ATwo open questions before this gets merged.
One, is it OK to make changes to multiple packages in one PR? The update to
wsis what I actually wanted to make but doing so required exposing the interface fromnode. Changing the function signature innodebroke tests on several other packages, so I fixed those at the same time. I can submit separate PRs if need be.Two, is there a convention about where to put named interfaces for structures that aren't named in the actual library being described? Node does not actually define an
AddressInfotype anywhere in its codebase or documentation, but it's an object shape that's used in many places so it makes sense to have one in the typings. I'm just not sure where it belongs. I moved it intonetbecause that made sense to me.