Skip to content

feat: add typescript types#197

Open
gameroman wants to merge 4 commits into
pillarjs:masterfrom
gameroman:add-types
Open

feat: add typescript types#197
gameroman wants to merge 4 commits into
pillarjs:masterfrom
gameroman:add-types

Conversation

@gameroman

Copy link
Copy Markdown

No description provided.

@socket-security

socket-security Bot commented May 9, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​tsconfig/​node18@​18.2.61001007183100
Addednpm/​@​types/​node@​18.19.1301001008195100
Addednpm/​expect-type@​1.4.010010010085100
Addednpm/​@​arethetypeswrong/​cli@​0.18.59910010087100

View full report

@bjohansebas

Copy link
Copy Markdown
Member

Hey, could you add the TypeScript test infrastructure we added in on-finished? Sorry for the delay. jshttp/on-finished#69

@socket-security

socket-security Bot commented Jul 13, 2026

Copy link
Copy Markdown

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

Comment thread test/types.ts
Comment on lines +19 to +20
// typescript has no way to infer the types automatically
router.get<ErrorRequestHandler>("/", function (err, req, res, next) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Basically, typescript can not automatically infer that the callback type is ErrorRequestHandler so if you don't provide the type param, it'll just infer it's params as any

The only way to solve this is to change everything completely, changing callback's param to an object like { err, req, res, next }, instead of 4 different params, this is what hono, elysiajs and other do

This would obviously require a new major so I haven't touched anything there

So just letting know that the current logic cannot be fully expressed in typescript without manually providing the type parameter on the user's side

@gameroman
gameroman marked this pull request as ready for review July 13, 2026 12:29
@UlisesGascon UlisesGascon self-assigned this Jul 14, 2026

@bjohansebas bjohansebas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good start! I found a few nits while doing the code review

Comment thread lib/route.d.ts Outdated
Comment thread index.d.ts Outdated
Comment thread index.d.ts Outdated
Comment thread index.d.ts
}

declare const router: RouterConstructor
export = router

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're mixing export = with other exports, which will cause issues for anyone using skipLibCheck: false. @tsconfig/node18 enables skipLibCheck by default, which is why the CI doesn't catch this error. If you need help figuring out how to fix it, let me know.

this applies to both files.

Comment thread lib/route.d.ts Outdated
Comment thread index.d.ts Outdated
Comment thread index.d.ts Outdated
Comment thread lib/route.d.ts
export type RouteMethod<T> = <F extends Handler = RequestHandler>(handler: F) => T

export interface Route {
path: string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like us to use the Path type from index.d.ts here as well, but unfortunately we'd end up breaking more than we'd gain, since it's been this way in the Express types for years.

Comment thread lib/route.d.ts Outdated
Comment thread test/types.ts
gameroman and others added 2 commits July 15, 2026 12:47
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
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 this pull request may close these issues.

3 participants