X Tutup
Skip to content

connect: Add NextFunction for next, fix err parameter#24883

Merged
RyanCavanaugh merged 1 commit intoDefinitelyTyped:masterfrom
EvanHahn:connect-nextFunction
Apr 17, 2018
Merged

connect: Add NextFunction for next, fix err parameter#24883
RyanCavanaugh merged 1 commit intoDefinitelyTyped:masterfrom
EvanHahn:connect-nextFunction

Conversation

@EvanHahn
Copy link
Contributor

  • 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).

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: code sample, next documentation
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

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

type NextFunction = (err?: any) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't error null | Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of these are valid in Connect:

next();
next(null);
next(new Error("Something bad happened!"));
next(404);
next(true);

@typescript-bot typescript-bot added the Popular package This PR affects a popular package (as counted by NPM download counts). label Apr 10, 2018
@typescript-bot
Copy link
Contributor

typescript-bot commented Apr 10, 2018

@EvanHahn Thank you for submitting this PR!

🔔 @SomaticIT - 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 typescript-bot added Awaiting reviewer feedback Unmerged The author did not merge the PR when it was ready. labels Apr 10, 2018
@typescript-bot
Copy link
Contributor

After 5 days, no one has reviewed the PR 😞. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience!

@RyanCavanaugh RyanCavanaugh merged commit 23c8bbf into DefinitelyTyped:master Apr 17, 2018
export type ErrorHandleFunction = (err: Error, req: http.IncomingMessage, res: http.ServerResponse, next: Function) => void;
export type NextHandleFunction = (req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
export type ErrorHandleFunction = (err: any, req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
export type HandleFunction = SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction;
Copy link

Choose a reason for hiding this comment

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

@EvanHahn I think that req in the callbacks should use a subtype of http.IncomingMessage which also has req.originalUrl: string.

In order to make middleware easier to write to be agnostic of the route, when the fn is invoked, the req.url will be altered to remove the route part (and the original will be available as req.originalUrl). For example, if fn is used at the route /foo, the request for /foo/bar will invoke fn with req.url === '/bar' and req.originalUrl === '/foo/bar'.
-- https://www.npmjs.com/package/connect#appuseroute-fn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks right to me. Would you be able to make a pull request? I don't think I'll have time, but could review it.

Copy link

Choose a reason for hiding this comment

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

I've never done pull requests before... But I'll try to do it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to email me at me@evanhahn.com if I can help!

@EvanHahn EvanHahn deleted the connect-nextFunction branch November 12, 2019 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Popular package This PR affects a popular package (as counted by NPM download counts). Unmerged The author did not merge the PR when it was ready.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup