tsndr / cloudflare-worker-router

A super lightweight router (1.0K) with middleware support and ZERO dependencies for Cloudflare Workers.
MIT License
227 stars 30 forks source link

Types not available #21

Closed richardwillars closed 2 years ago

richardwillars commented 2 years ago

I might be missing something obvious, but when trying to define a route handler in a separate file, it's not possible in Typescript at the moment as the types aren't exported.

I'm trying to do this:

export const handler: RouterHandler = async ({ req, res }) => {}

But unfortunately, when doing:

import { RouterHandler } from '@tsndr/cloudflare-worker-router'

I get a type not found error. When I look at the d.ts file I can see all the types, but none of them are exported from there.. I think that might be the issue.

When I change it from this:

/**
 * Handler Function
 *
 * @callback RouterHandler
 * @param {RouterContext} ctx
 * @returns {Promise<void> | void}
 */
interface RouterHandler {
    (ctx: RouterContext): Promise<void> | void
}

To this:

/**
 * Handler Function
 *
 * @callback RouterHandler
 * @param {RouterContext} ctx
 * @returns {Promise<void> | void}
 */
export interface RouterHandler {
    (ctx: RouterContext): Promise<void> | void
}

It works, but I'm not sure that's how you're actually supposed to do it! You would have thought anything in d.ts would be 'public' and importable