hono icon indicating copy to clipboard operation
hono copied to clipboard

feat(types): make Hono client's $url return the exact URL type

Open miyaji255 opened this issue 2 months ago • 4 comments

Summary

This pull request enhances the type safety and expressiveness of the client-side URL generation in the Hono framework. The main improvement is the introduction of a new TypedURL type, which allows the client to generate URLs with strongly-typed protocol, host, port, path, and query parameters based on the application's route schema and the provided base URL. Several generics and utility types are introduced to propagate this type information throughout the client, ensuring that URL generation is accurate and type-checked at compile time.

esbuild v0.15.18 doesn't support const type parameters, so I updated esbuild.

Motivation

I wanted to add types so that keys used with SWR would be easy to reuse in other parts of the codebase. However, $url did not preserve that type information, so I created this PR.

  • [x] Add tests
  • [x] Run tests
  • [x] bun run format:fix && bun run lint:fix to format the code
  • [ ] Add TSDoc/JSDoc to document the code

miyaji255 avatar Oct 31 '25 17:10 miyaji255

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 91.55%. Comparing base (6efc564) to head (d322285).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #4502   +/-   ##
=======================================
  Coverage   91.55%   91.55%           
=======================================
  Files         172      172           
  Lines       11225    11225           
  Branches     3261     3261           
=======================================
  Hits        10277    10277           
  Misses        947      947           
  Partials        1        1           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Oct 31 '25 17:10 codecov[bot]

Hi @miyaji255

This is super interesting. I'll look at it deeply later.

yusukebe avatar Nov 01 '25 22:11 yusukebe

Sorry for being late. Anyway, this change is not a "fix", but a "feat". It's a new feature.

yusukebe avatar Nov 12 '25 08:11 yusukebe

@miyaji255

This is awesome! We can include this feature in the next minor release. So, I'll merge when preparing to release it. Thank you!

yusukebe avatar Nov 26 '25 11:11 yusukebe