nuxt-open-fetch icon indicating copy to clipboard operation
nuxt-open-fetch copied to clipboard

fix: type helpers

Open adamdehaven opened this issue 8 months ago • 2 comments

Response type helper

Update the generated client Response interface to include all valid 2xx response codes. Resolves #88.

RequestBody type helper

Also updates the client RequestBody interface to handle required and optional requestBody

// An operation with optional request body
type Operation1 = {
  requestBody?: { content: { 'application/json': { name: string } } }
}

// An operation with required request body
type Operation2 = {
  requestBody: { content: { 'application/json': { id: number } } }
}

// Original version:
type Test1 = Operation1['requestBody'] extends { content: { 'application/json': infer U } } ? U : never
// Result: never (fails)

// Updated version:
type Test2 = Operation1 extends { requestBody?: { content: { 'application/json': infer U } } } ? U : never
// Result: { name: string } (works)

The updated version works for both required and optional request bodies

adamdehaven avatar Mar 12 '25 17:03 adamdehaven

@adamdehaven is attempting to deploy a commit to the Taras Batenkov's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Mar 12 '25 17:03 vercel[bot]

@enkot this allows proper interfaces for non-200 responses, e.g. to support something like this:

// Assume this endpoint returns a `201` response code
const myApp: MyClientResponse<'create-application'> = {
  // interface now appears
}

adamdehaven avatar Mar 12 '25 18:03 adamdehaven