From 2b274662e9ea8ed32fcb22ec9becf18bd22e82c4 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Mon, 21 Aug 2023 00:19:04 +0900 Subject: [PATCH] fix(client): ignore `header` and `cookie` types (#1359) * fix(client): ignore `header` and `cookie` types * denoify --- deno_dist/client/types.ts | 6 +++++- deno_dist/types.ts | 12 +++++++----- src/client/client.test.ts | 12 ++++++++++++ src/client/types.ts | 6 +++++- src/types.ts | 8 ++++---- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/deno_dist/client/types.ts b/deno_dist/client/types.ts index a5815049..89fb15cb 100644 --- a/deno_dist/client/types.ts +++ b/deno_dist/client/types.ts @@ -22,7 +22,11 @@ type ClientRequest = { [M in keyof S]: S[M] extends { input: infer R; output: infer O } ? RemoveBlankRecord extends never ? (args?: {}, options?: ClientRequestOptions) => Promise> - : (args: R, options?: ClientRequestOptions) => Promise> + : ( + // Client does not support `header` and `cookie` + args: Omit, + options?: ClientRequestOptions + ) => Promise> : never } diff --git a/deno_dist/types.ts b/deno_dist/types.ts index 5cd5315b..edbd4f3d 100644 --- a/deno_dist/types.ts +++ b/deno_dist/types.ts @@ -98,7 +98,7 @@ export interface HandlerInterface< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, - I4 extends Input = I2 & I3 + I4 extends Input = I & I2 & I3 >( ...handlers: [H, H, H, H] ): Hono>, BasePath> @@ -111,7 +111,7 @@ export interface HandlerInterface< I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, - I5 extends Input = I3 & I4 + I5 extends Input = I & I2 & I3 & I4 >( ...handlers: [H, H, H, H, H] ): Hono>, BasePath> @@ -156,7 +156,7 @@ export interface HandlerInterface< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, - I4 extends Input = I2 & I3 + I4 extends Input = I & I2 & I3 >( path: P, ...handlers: [ @@ -175,7 +175,7 @@ export interface HandlerInterface< I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, - I5 extends Input = I3 & I4 + I5 extends Input = I & I2 & I3 & I4 >( path: P, ...handlers: [ @@ -430,7 +430,9 @@ export type UndefinedIfHavingQuestion = T extends `${infer _}?` ? string | un ////// ////// //////////////////////////////////////// -export type ExtractSchema = UnionToIntersection ? S : never> +export type ExtractSchema = UnionToIntersection< + T extends Hono ? S : never +> //////////////////////////////////////// ////// ////// diff --git a/src/client/client.test.ts b/src/client/client.test.ts index 21d298bb..7b3ad5fd 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -25,6 +25,18 @@ describe('Basic - JSON', () => { const route = app .post( '/posts', + // Client does not support `cookie` + validator('cookie', () => { + return {} as { + debug: string + } + }), + // Client does not support `header` + validator('header', () => { + return {} as { + 'x-request-id': string + } + }), validator('json', () => { return {} as { id: number diff --git a/src/client/types.ts b/src/client/types.ts index 2092ceb0..b303d5f4 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -22,7 +22,11 @@ type ClientRequest = { [M in keyof S]: S[M] extends { input: infer R; output: infer O } ? RemoveBlankRecord extends never ? (args?: {}, options?: ClientRequestOptions) => Promise> - : (args: R, options?: ClientRequestOptions) => Promise> + : ( + // Client does not support `header` and `cookie` + args: Omit, + options?: ClientRequestOptions + ) => Promise> : never } diff --git a/src/types.ts b/src/types.ts index 098deb63..c3aff44c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -98,7 +98,7 @@ export interface HandlerInterface< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, - I4 extends Input = I2 & I3 + I4 extends Input = I & I2 & I3 >( ...handlers: [H, H, H, H] ): Hono>, BasePath> @@ -111,7 +111,7 @@ export interface HandlerInterface< I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, - I5 extends Input = I3 & I4 + I5 extends Input = I & I2 & I3 & I4 >( ...handlers: [H, H, H, H, H] ): Hono>, BasePath> @@ -156,7 +156,7 @@ export interface HandlerInterface< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, - I4 extends Input = I2 & I3 + I4 extends Input = I & I2 & I3 >( path: P, ...handlers: [ @@ -175,7 +175,7 @@ export interface HandlerInterface< I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I2 & I3, - I5 extends Input = I3 & I4 + I5 extends Input = I & I2 & I3 & I4 >( path: P, ...handlers: [