kwhitley / itty-router

A little router.
MIT License
1.71k stars 77 forks source link

incompatible with itty-cors #137

Closed rwv closed 1 year ago

rwv commented 1 year ago
import { Router } from "itty-router";
import { createCors } from "itty-cors";

// create CORS handlers
const { preflight, corsify } = createCors({});

// Create a new router
const router = Router();
// Add CORS headers to all responses
router.all("*", preflight);

cause error:

src/router/index.ts:16:17 - error TS2345: Argument of type '(r: Request) => Response' is not assignable to parameter of type 'RouteHandler'.
  Types of parameters 'r' and 'request' are incompatible.
    Type 'IRequest' is missing the following properties from type 'Request': clone, headers, redirect, fetcher, and 8 more.

16 router.all("*", preflight);
                   ~~~~~~~~~

works fine in itty-router 2.x

dannyrb commented 1 year ago

I have a similar issue when trying to create new Request(request, { /** **/ })

Where IRequest cannot be supplied for Request

kwhitley commented 1 year ago

Thanks guys, I'll be sure to address this as part of the v4.x migration! https://github.com/kwhitley/itty-router/pull/148

kwhitley commented 1 year ago

Imported, modified to IRequest, and confirmed working in 4.x: image

kwhitley commented 1 year ago

Thanks all - this has been fully addressed in the v4.x next branch that's pending release!

Strict mode is no problem! :)

image

kwhitley commented 1 year ago

For complete v4.x docs, start here:

https://ity.dev/itty-router

Expect the @next branch to drop into main in the next couple days, barring any major issues found by the community. The types are finally sorted!