itty-router-extras icon indicating copy to clipboard operation
itty-router-extras copied to clipboard

Property 'project' does not exist on type 'Request'

Open andyjessop opened this issue 2 years ago • 2 comments

I'm unable to get type inference working on the withParams helper:

import { Router } from 'itty-router';
import { withParams } from 'itty-router-extras';

export default {
  fetch
};

const router = Router();

router.get('/projects/:project/deployments', withParams, async ({ project }) => {
  console.log(project);
  return new Response();
});

Gives me this error:

Property 'project' does not exist on type 'Request'. ts(2339)

andyjessop avatar Jun 02 '22 19:06 andyjessop

you can extend the Request interface and add 'project' type and assign it to 'any' and make it optional

bkyerv avatar Aug 23 '22 13:08 bkyerv

In the middle of https://github.com/kwhitley/itty-router/pull/121, where I may be rewriting all the types for core (I'm certainly doing it for extras, that are being brought into core), so this is helpful, thanks!

kwhitley avatar Sep 16 '22 16:09 kwhitley