Skip to content

[Bug]: Node.js sample fails npm run build because route params are typed optional #124

Description

@ShuoRen-TT

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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions