feat(mbe): add typing for typed request handlers#20
Merged
mohammadalfaiyazbitgo merged 1 commit intomasterfrom Jun 10, 2025
Merged
feat(mbe): add typing for typed request handlers#20mohammadalfaiyazbitgo merged 1 commit intomasterfrom
mohammadalfaiyazbitgo merged 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds TypeScript typing support for Master API request handlers and integrates those types into the shared response middleware and the generate-wallet flow.
- Refactors
withResponseHandlerto use a generic typed request instead of raw Express/BitGo unions - Introduces
MasterApiSpecRouteHandler,MasterApiSpecRouteRequestand a generic alias for routing types - Updates the generate-wallet handler to consume
req.decodedfrom the typed request instead ofreq.body
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/shared/responseHandler.ts | Middleware now expects GenericMasterApiSpecRouteRequest and casts Express req |
| src/masterBitgoExpress/routers/masterApiSpec.ts | Defines new typed handler/request aliases and applies them to router.post call |
| src/masterBitgoExpress/generateWallet.ts | Handler signature switched to use MasterApiSpecRouteRequest<'v1.wallet.generate','post'> |
Comments suppressed due to low confidence (5)
src/shared/responseHandler.ts:19
- The
ServiceFunctiontype is now locked toMasterApiSpecRouteRequest<any, any>, removing the ability to directly handle plainExpress.RequestorBitGoRequest. Consider makingServiceFunctiongeneric or restoring a union to support other request shapes.
req: MasterApiSpecRouteRequest<any, any>,
src/shared/responseHandler.ts:30
- The middleware signature no longer includes
BitGoRequest, but castsreqlater. You might instead type this parameter asGenericMasterApiSpecRouteRequestto avoid casting and make the handler’s contract clearer.
return async (req: Request, res: EncodedResponse, next: NextFunction) => {
src/masterBitgoExpress/routers/masterApiSpec.ts:99
- [nitpick] The type alias
MasterApiSpecshadows the constant of the same name. Consider renaming the type alias (e.g.MasterApiSpecType) to avoid confusion.
export type MasterApiSpec = typeof MasterApiSpec;
src/masterBitgoExpress/routers/masterApiSpec.ts:111
- [nitpick]
GenericMasterApiSpecRouteRequestis quite verbose. A shorter alias (e.g.AnyMasterApiRequest) might improve readability.
export type GenericMasterApiSpecRouteRequest = MasterApiSpecRouteRequest<any, any>;
src/masterBitgoExpress/routers/masterApiSpec.ts:125
- The new typed handler is not covered by existing tests. Consider adding a unit or integration test to verify that
req.decodedproperties are correctly populated and handled.
withResponseHandler(async (req: GenericMasterApiSpecRouteRequest) => {
Comment on lines
+30
to
+32
| return async (req: Request, res: EncodedResponse, next: NextFunction) => { | ||
| try { | ||
| const result = await Promise.resolve(fn(req, res, next)); | ||
| const result = await fn(req as unknown as GenericMasterApiSpecRouteRequest, res, next); |
There was a problem hiding this comment.
Casting via unknown is a workaround; consider updating the middleware’s req type directly to GenericMasterApiSpecRouteRequest so you can call fn(req, ...) without an intermediate cast.
pranavjain97
approved these changes
Jun 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: WP-4622