unjs / unjs/fetchdts

Add generic type to return of json

Open
#142 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
126
Forks
7
Avg merge
6h 30m
Merged PRs (30d)
15

Description

🆒 Your use case

The behaviour of

event.req.json<{ key: string }>()

should be

json: <T = any>() => Promise<T>
🆕 The solution you'd like

event.req.json() returns Promise<Body> where Body is inferred from EventHandlerRequest["body"] via TypedServerRequest → fetchdts's TypedRequest<Body, Headers>

🔍 Alternatives you've considered

No response

ℹ️ Additional info

Related: https://github.com/h3js/h3/issues/1256

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing EventHandlerRequest["body"] through TypedServerRequest to fetchdts's TypedRequest<Body, Headers>, focusing on the json() type shown in the issue. Confirm how the generic should interact with the inferred Body type. Done when event.req.json<{ key: string }>() is typed as Promise<{ key: string }> while the existing inferred return remains supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.