Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Request and Obj types? #38

Closed
youraerials opened this issue May 31, 2021 · 5 comments
Closed

Export Request and Obj types? #38

youraerials opened this issue May 31, 2021 · 5 comments

Comments

@youraerials
Copy link

Hi,

We LOVE itty! Would it be possible to export your types from your .d.ts file? We often do handlers in separate handler files and we'd love to be able to do things like this:

import { Request as IttyRequest } from 'itty-router';
...
async buildSomeResponse(req: IttyRequest): Promise<Response> { ... }

VSCode in particular gets confused with the type of the Request arg, and barking about req.query not existing in an example like the above.

Thanks!

@kwhitley
Copy link
Owner

kwhitley commented Jun 1, 2021

Hey @youraerials - glad you like it!!

So confession time, I'm one of those punks that still loves the chaos that is pure JS... thus rely on my much more sophisticated friends to fill in TS support. If you happen to know what it would take to solve this, I always welcome a PR (and love to be able to add folks to the README credits), or even code suggestion here in the issue. Otherwise, I'll definitely do what I can, but it may take just a bit longer till it's sorted... :)

@carlsonorozco
Copy link

Hi @youraerials,

Do you have a workaround here? Got the same issue. TIA

@kwhitley
Copy link
Owner

kwhitley commented Aug 9, 2021

So in short now that I'm able to get back to this issue... yes, definitely no issue exporting the interfaces - this will be going out with the next release in a day or so. While I'm on the subject, please verify this interface looks fine for Request? I'm not 100% on TS syntax, but I'm attempting to add optional methods (arrayBuffer() ... text()). If that doesn't look like broken syntax to you... I think we're good to go.

export interface Request {
  method?: string
  params?: Obj
  query?: Obj
  url: string

  arrayBuffer?(): Promise
  blob?(): Promise
  formData?(): Promise
  json?(): Promise
  text?(): Promise
}

@kwhitley
Copy link
Owner

kwhitley commented Aug 9, 2021

@carlsonorozco @youraerials

@kwhitley
Copy link
Owner

Should be exported as of 2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants