feat: add typescript types#197
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Hey, could you add the TypeScript test infrastructure we added in on-finished? Sorry for the delay. jshttp/on-finished#69 |
|
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. |
| // typescript has no way to infer the types automatically | ||
| router.get<ErrorRequestHandler>("/", function (err, req, res, next) { |
There was a problem hiding this comment.
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
bjohansebas
left a comment
There was a problem hiding this comment.
Good start! I found a few nits while doing the code review
| } | ||
|
|
||
| declare const router: RouterConstructor | ||
| export = router |
There was a problem hiding this comment.
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.
| export type RouteMethod<T> = <F extends Handler = RequestHandler>(handler: F) => T | ||
|
|
||
| export interface Route { | ||
| path: string |
There was a problem hiding this comment.
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.
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
No description provided.