nuxt-open-fetch
nuxt-open-fetch copied to clipboard
fix: type helpers
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 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.
@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
}