From 1d16b84b62b55edd25a0fddccd48617eb657cef3 Mon Sep 17 00:00:00 2001 From: m-shaka Date: Sun, 30 Jun 2024 07:50:45 +0900 Subject: [PATCH] fix(client): set Path as the default of Original (#3058) --- src/client/types.test.ts | 34 ++++++++++++++++++++++++++++++++++ src/client/types.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/client/types.test.ts b/src/client/types.test.ts index 13904f0a..7619dabc 100644 --- a/src/client/types.test.ts +++ b/src/client/types.test.ts @@ -23,3 +23,37 @@ describe('WebSockets', () => { >().toEqualTypeOf(true) }) }) + +describe('without the leading slash', () => { + const app = new Hono() + .get('foo', (c) => c.json({})) + .get('foo/bar', (c) => c.json({})) + .get('foo/:id/baz', (c) => c.json({})) + const client = hc('') + it('`foo` should have `$get`', () => { + expectTypeOf(client.foo).toHaveProperty('$get') + }) + it('`foo.bar` should not have `$get`', () => { + expectTypeOf(client.foo.bar).toHaveProperty('$get') + }) + it('`foo[":id"].baz` should have `$get`', () => { + expectTypeOf(client.foo[':id'].baz).toHaveProperty('$get') + }) +}) + +describe('with the leading slash', () => { + const app = new Hono() + .get('/foo', (c) => c.json({})) + .get('/foo/bar', (c) => c.json({})) + .get('/foo/:id/baz', (c) => c.json({})) + const client = hc('') + it('`foo` should have `$get`', () => { + expectTypeOf(client.foo).toHaveProperty('$get') + }) + it('`foo.bar` should not have `$get`', () => { + expectTypeOf(client.foo.bar).toHaveProperty('$get') + }) + it('`foo[":id"].baz` should have `$get`', () => { + expectTypeOf(client.foo[':id'].baz).toHaveProperty('$get') + }) +}) diff --git a/src/client/types.ts b/src/client/types.ts index 0b76804b..8f2c77c5 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -146,7 +146,7 @@ export type InferRequestOptionsType = T extends ( type PathToChain< Path extends string, E extends Schema, - Original extends string = '' + Original extends string = Path > = Path extends `/${infer P}` ? PathToChain : Path extends `${infer P}/${infer R}`