question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support additional generic for typing incoming body & query

See original GitHub issue

would support something like this:

export default defineEventHandler<{ result: string }, { foo: string }>(async event => {
  const { foo } = await useBody(event)
  return {
    result: foo
  }
})

const result = await $fetch('/api/test', {
  body: {
    // auto-completing body, requiring 
  }
})

Follow-up tasks

  • add support for typing query/body in Nitro generated types & ohmyfetch (via options)

possibly could also consider params?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
kevinmarreccommented, Jun 12, 2022

I just released h3-typebox (source) 🚀

Feedbacks are welcome !

2reactions
pi0commented, Aug 4, 2022

I would personnaly rename it to h3-validator (but fine with h3-typebox if listed in Readme as validator options) and support the new event object @kevinmarrec 😊

This issue is still open for a built-in validation. Conventionally, by using the integration name in h3-[integration] we can support other possible validators from community.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typed Express Request and Response with ... - In Plain English
Request .body & query; A small security note on incoming requests ... this new interface it's possible to use generics to type the...
Read more >
Model Binding | FastEndpoints
Query string parameters from the incoming request are bound automatically to the request DTO properties. See here for the types of properties supported...
Read more >
How to cast req.query parameters in Express using Typescript
You could define the types that you will expect on the ReqBody , ReqQuery and the other generics of Request type.
Read more >
Type-safe API mocking with Mock Service Worker and ...
Response body type. Request parameters. Let's take a look at the UPDATE /post/:postId request that utilizes all three said generics:.
Read more >
Accepting Raw Request Body Content in ASP.NET Core API ...
NET Core has a clean and more generic way to handle custom formatting ... body and perform your own deserialization on the inbound...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found