Describe the bug
The Node.js sample fails strict TypeScript compilation because required route parameters are inferred as optional.
npm run build
src/api/checkout.ts(...): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
src/api/order.ts(...): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
src/api/testing.ts(...): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
There are 12 errors in total:
- 7 in
src/api/checkout.ts
- 4 in
src/api/order.ts
- 1 in
src/api/testing.ts
To reproduce
cd rest/nodejs
npm ci
npm run build
Root cause
The handlers are declared with a generic Hono Context and read IDs with:
const id = c.req.param("id");
For an untyped route context, Hono returns string | undefined. The routes use zValidator("param", IdParamSchema, ...), but that validated input type does not flow into the separately declared class handlers. The code then passes the optional value to data functions that require string.
Expected behavior
npm run build should type-check successfully, and handlers should explicitly narrow or consume validated required route parameters before using them.
Proposed fix
- narrow required
id parameters in checkout, order, and testing handlers
- add focused tests for missing and present IDs
- add a follow-up Node build/test CI job so regressions are caught automatically
Related work
Code of Conduct
Describe the bug
The Node.js sample fails strict TypeScript compilation because required route parameters are inferred as optional.
There are 12 errors in total:
src/api/checkout.tssrc/api/order.tssrc/api/testing.tsTo reproduce
cd rest/nodejs npm ci npm run buildRoot cause
The handlers are declared with a generic Hono
Contextand read IDs with:For an untyped route context, Hono returns
string | undefined. The routes usezValidator("param", IdParamSchema, ...), but that validated input type does not flow into the separately declared class handlers. The code then passes the optional value to data functions that requirestring.Expected behavior
npm run buildshould type-check successfully, and handlers should explicitly narrow or consume validated required route parameters before using them.Proposed fix
idparameters in checkout, order, and testing handlersRelated work
Code of Conduct