-
-
Notifications
You must be signed in to change notification settings - Fork 54
feat: add types #88
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
base: master
Are you sure you want to change the base?
feat: add types #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /// <reference types="node" /> | ||
|
|
||
| import { IncomingMessage, ServerResponse } from "node:http"; | ||
|
|
||
| declare function finalhandler( | ||
| req: IncomingMessage, | ||
| res: ServerResponse, | ||
| options?: finalhandler.Options | ||
| ): (err?: any) => void; | ||
|
|
||
| declare namespace finalhandler { | ||
| interface Options { | ||
| env?: string | undefined; | ||
| onerror?: | ||
| | ((err: any, req: IncomingMessage, res: ServerResponse) => void) | ||
| | undefined; | ||
| } | ||
| } | ||
|
|
||
| export = finalhandler; | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |||||||
| "author": "Douglas Christopher Wilson <[email protected]>", | ||||||||
| "license": "MIT", | ||||||||
| "repository": "pillarjs/finalhandler", | ||||||||
| "type": "commonjs", | ||||||||
| "main": "index.js", | ||||||||
| "types": "index.d.ts", | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe types would be resolved automatically even without this entry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least in my PR |
||||||||
| "dependencies": { | ||||||||
| "debug": "^4.4.0", | ||||||||
| "encodeurl": "^2.0.0", | ||||||||
|
|
@@ -14,21 +17,27 @@ | |||||||
| "statuses": "^2.0.1" | ||||||||
| }, | ||||||||
| "devDependencies": { | ||||||||
| "@arethetypeswrong/cli": "^0.17.4", | ||||||||
| "@tsconfig/node18": "^18.2.4", | ||||||||
| "@types/node": "^22.13.10", | ||||||||
Phillip9587 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| "eslint": "7.32.0", | ||||||||
| "eslint-config-standard": "14.1.1", | ||||||||
| "eslint-plugin-import": "2.26.0", | ||||||||
| "eslint-plugin-markdown": "2.2.1", | ||||||||
| "eslint-plugin-node": "11.1.0", | ||||||||
| "eslint-plugin-promise": "5.2.0", | ||||||||
| "eslint-plugin-standard": "4.1.0", | ||||||||
| "expect-type": "^1.2.0", | ||||||||
| "mocha": "^11.0.1", | ||||||||
| "nyc": "^17.1.0", | ||||||||
| "supertest": "^7.0.0" | ||||||||
| "supertest": "^7.0.0", | ||||||||
| "typescript": "^5.8.2" | ||||||||
| }, | ||||||||
| "files": [ | ||||||||
| "LICENSE", | ||||||||
| "HISTORY.md", | ||||||||
| "index.js" | ||||||||
| "index.js", | ||||||||
| "index.d.ts" | ||||||||
|
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| ], | ||||||||
| "engines": { | ||||||||
| "node": ">= 0.8" | ||||||||
|
|
@@ -38,6 +47,7 @@ | |||||||
| "test": "mocha --reporter spec --check-leaks test/", | ||||||||
| "test-ci": "nyc --reporter=lcovonly --reporter=text npm test", | ||||||||
| "test-cov": "nyc --reporter=html --reporter=text npm test", | ||||||||
| "test-inspect": "mocha --reporter spec --inspect --inspect-brk test/" | ||||||||
| "test-inspect": "mocha --reporter spec --inspect --inspect-brk test/", | ||||||||
| "test-types": "tsc --noEmit && attw --pack" | ||||||||
| } | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { IncomingMessage, ServerResponse, createServer } from "node:http"; | ||
| import { expectTypeOf } from "expect-type"; | ||
| import finalhandler, { Options } from ".."; | ||
|
|
||
| const req = {} as IncomingMessage; | ||
| const res = {} as ServerResponse; | ||
|
|
||
| const options: Options = { | ||
| env: "anEnv", | ||
| onerror: (err, req, res) => { | ||
| expectTypeOf(err).toBeAny(); | ||
| expectTypeOf(req).toEqualTypeOf<IncomingMessage>(); | ||
| expectTypeOf(res).toEqualTypeOf<ServerResponse>(); | ||
| }, | ||
| }; | ||
|
|
||
| expectTypeOf(options.env).toEqualTypeOf<string | undefined>(); | ||
|
|
||
| // finalhandler without options | ||
| { | ||
| const result = finalhandler(req, res); | ||
| expectTypeOf(result).toBeFunction(); | ||
| expectTypeOf(result).parameters.toEqualTypeOf<[any?]>(); | ||
| expectTypeOf(result).returns.toBeVoid(); | ||
| expectTypeOf(result).toBeCallableWith(new Error()); | ||
| } | ||
|
|
||
| // finalhandler with options | ||
| { | ||
| const result = finalhandler(req, res, options); | ||
| expectTypeOf(result).toBeFunction(); | ||
| expectTypeOf(result).parameters.toEqualTypeOf<[any?]>(); | ||
| expectTypeOf(result).returns.toBeVoid(); | ||
| expectTypeOf(result).toBeCallableWith(new Error()); | ||
| } | ||
|
|
||
| // serve-static-like request handler | ||
| declare function requestHandler( | ||
| request: IncomingMessage, | ||
| response: ServerResponse, | ||
| next: (err?: any) => void | ||
| ): any; | ||
|
|
||
| createServer((req, res) => { | ||
| requestHandler(req, res, finalhandler(req, res)); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "@tsconfig/node18/tsconfig.json", | ||
| "include": ["index.d.ts", "test/types.ts"] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.