Skip to content

feat: add typescript types - #197

Merged
bjohansebas merged 20 commits into
pillarjs:masterfrom
gameroman:add-types
Oct 17, 2026
Merged

bjohansebas merged 20 commits into
pillarjs:masterfrom
gameroman:add-types

Conversation

@gameroman

Copy link
Copy Markdown
Contributor

No description provided.

@socket-security

socket-security Bot commented May 9, 2026 •

Copy link
Copy Markdown

@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 Outdated
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
Contributor 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 Outdated
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 Outdated
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 Outdated
gameroman and others added 4 commits October 17, 2026 15:41
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
Comment thread test/types/request.ts Dismissed
@bjohansebas
bjohansebas merged commit 4064f28 into pillarjs:master Oct 17, 2026
16 checks passed
@gameroman
gameroman deleted the add-types branch October 21, 2026 02:41
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.

4 participants