router icon indicating copy to clipboard operation
router copied to clipboard

Add typescript definition

Open ilikejames opened this issue 2 years ago • 2 comments

A few years ago I had a quick attempt at adding types for this library. https://github.com/pillarjs/router/pull/76.

The http methods is copied from the methods library. I had hoped to use its types directly, but that proved tricky with building older versions of node, so instead it's a hard coded list copied from the library.

The types level tests are exhaustive, but let me know if there is anything I have missed.

There is a couple of assumptions made:

  • query parameters are always a string.
  • response is OutgoingMessage type.

I've limited the published types to [email protected] and greater due to some of the syntax being specific to this more recent version.

I had wanted to include @types/node as a peerDependency but it appears that was not removable via npm rm X --save-peer and would result in a build error in early versions of npm

Edit: Made a further change. It looks like in the tests there is a lot of

  req.newProperty = 'new value'

To facilitate that, I've updated RoutedRequest (on the second commit).

This might be better done by supplying a generic, but that could be a further later addition.

Edit: Sorry for all the pushes/builds. Should have closed the PR, and worked on the fork only.

ilikejames avatar Mar 28 '23 15:03 ilikejames

Is there any progress here? AFAIK This is the last non-dev dependency to get Express types moving.

reteps avatar Sep 21 '25 03:09 reteps

cc @ilikejames

reteps avatar Sep 21 '25 03:09 reteps