X Tutup
Skip to content

[connect] Add missing property originalUrl to req parameter#40776

Merged
orta merged 1 commit intoDefinitelyTyped:masterfrom
trygveaa:connect-req-add-originalUrl
Dec 17, 2019
Merged

[connect] Add missing property originalUrl to req parameter#40776
orta merged 1 commit intoDefinitelyTyped:masterfrom
trygveaa:connect-req-add-originalUrl

Conversation

@trygveaa
Copy link
Contributor

@trygveaa trygveaa commented Dec 2, 2019

This adds a new class IncomingMessage which extends from
http.IncomingMessage and adds the originalUrl property which was
previously missing. This new class is used for the req parameter in
HandleFunction.

The originalUrl property is added to req here:
https://github.com/senchalabs/connect/blob/3.4.0/index.js#L133

originalUrl is present in the version specified in these type definitions, so I didn't change the version.

Please fill in this template.

  • 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 (or tsc if no tslint.json is present).

Select one of these and delete the others:
If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/senchalabs/connect/blob/3.4.0/index.js#L133
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }. If for reason the any rule need to be disabled, disable it for that line using // tslint:disable-next-line [ruleName] and not for whole package so that the need for disabling can be reviewed.

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Dec 2, 2019
@typescript-bot
Copy link
Contributor

typescript-bot commented Dec 2, 2019

@trygveaa Thank you for submitting this PR!

🔔 @SomaticIT @EvanHahn - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

Comparison details 📊
master #40776 diff
Batch compilation
Memory usage (MiB) 63.6 63.5 -0.2%
Type count 8398 8419 0%
Assignability cache size 901 903 0%
Language service
Samples taken 89 89 0%
Identifiers in tests 89 89 0%
getCompletionsAtPosition
    Mean duration (ms) 308.4 308.6 0.0%
    Mean CV 11.8% 10.9%
    Worst duration (ms) 439.9 388.8 -11.6%
    Worst identifier http app
getQuickInfoAtPosition
    Mean duration (ms) 305.8 309.8 +1.3%
    Mean CV 10.4% 11.9% +14.7%
    Worst duration (ms) 361.7 371.3 +2.7%
    Worst identifier IncomingMessage res

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Dec 2, 2019
Copy link
Contributor

@EvanHahn EvanHahn left a comment

Choose a reason for hiding this comment

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

Rejecting because I have a question:

Should we test that a request handler still works with http.IncomingMessage? For example, should we have a test like this?

app.use((req: http.IncomingMessage, res: http.ServerResponse) => {
  console.log(req, res);
  res.end();
});

@trygveaa
Copy link
Contributor Author

trygveaa commented Dec 5, 2019

@EvanHahn: Not sure if it's a question for me, or another maintainer. But sure, I can add that test if you want. I agree that it's a good idea.

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Awaiting reviewer feedback labels Dec 5, 2019
@typescript-bot
Copy link
Contributor

@trygveaa One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you!

This adds a new class IncomingMessage which extends from
http.IncomingMessage and adds the originalUrl property which was
previously missing. This new class is used for the req parameter in
HandleFunction.

The originalUrl property is added to req here:
https://github.com/senchalabs/connect/blob/3.4.0/index.js#L133
@trygveaa trygveaa force-pushed the connect-req-add-originalUrl branch from 3e3533e to fe6e40c Compare December 5, 2019 18:23
@trygveaa
Copy link
Contributor Author

trygveaa commented Dec 5, 2019

@EvanHahn: I've added the test.

@typescript-bot
Copy link
Contributor

🔔 @EvanHahn - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate?

export type ServerHandle = HandleFunction | http.Server;

export class IncomingMessage extends http.IncomingMessage {
originalUrl?: http.IncomingMessage["url"];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a TypeScript expert. What does this line do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

http.IncomingMessage["url"] is a reference to the type of the url property in http.IncomingMessage, so it's setting the type of originalUrl to be the same as the type of url. It's called lookup types, documented here.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Merge:Express labels Dec 5, 2019
@typescript-bot
Copy link
Contributor

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!

@orta
Copy link
Collaborator

orta commented Dec 17, 2019

Looks good and thanks for the test to verify existing code doesn't break 👍

@orta orta merged commit 7408c5d into DefinitelyTyped:master Dec 17, 2019
@trygveaa trygveaa deleted the connect-req-add-originalUrl branch December 17, 2019 13:21
@typescript-bot
Copy link
Contributor

I just published @types/connect@3.4.33 to npm.

declare namespace createServer {
export type ServerHandle = HandleFunction | http.Server;

export class IncomingMessage extends http.IncomingMessage {

Choose a reason for hiding this comment

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

This should be "implements" as http.IncomingMessage is an interface.

My code will no longer compile in typescript 3.7.2 because of this issue.

Full error is "node_modules/@types/connect/index.d.ts(21,42): error TS2689: Cannot extend an in
terface 'http.IncomingMessage'. Did you mean 'implements'?"

Please can we fix this ASAP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the types in this repo, http.IncomingMessage is a class. Where are you getting your types from?

Choose a reason for hiding this comment

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

Ah thanks for that. Turns out we were using an older version of node @types where the http.IncomingMessage was an interface. Thanks for your prompt response

trygveaa added a commit to trygveaa/typescript that referenced this pull request Dec 18, 2019
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
trygveaa added a commit to trygveaa/typescript that referenced this pull request Dec 18, 2019
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
kevinmarrec pushed a commit to nuxt/typescript that referenced this pull request Dec 18, 2019
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
venus-heaven added a commit to venus-heaven/nuxt-Typescript that referenced this pull request Apr 18, 2024
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
snowman074 pushed a commit to snowman074/typescript that referenced this pull request Mar 14, 2025
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
snow-man1120 added a commit to snow-man1120/typescript that referenced this pull request Mar 22, 2025
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
hall1210 added a commit to hall1210/typescript that referenced this pull request Aug 14, 2025
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
DevNucleus86 added a commit to DevNucleus86/typescript that referenced this pull request Mar 6, 2026
connect now has it's own IncomingMessage class which inherits from http
and includes the originalUrl property. The request instances here are
coming from connect, so they should use this class.

The IncomingMessage class from connect was added in
DefinitelyTyped/DefinitelyTyped#40776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Popular package This PR affects a popular package (as counted by NPM download counts). Revision needed This PR needs code changes before it can be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup