0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

fix(client): set Path as the default of Original (#3058)

This commit is contained in:
m-shaka 2024-06-30 07:50:45 +09:00 committed by GitHub
parent 2d3bc55954
commit 1d16b84b62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -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<typeof app>('')
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<typeof app>('')
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')
})
})

View File

@ -146,7 +146,7 @@ export type InferRequestOptionsType<T> = T extends (
type PathToChain<
Path extends string,
E extends Schema,
Original extends string = ''
Original extends string = Path
> = Path extends `/${infer P}`
? PathToChain<P, E, Path>
: Path extends `${infer P}/${infer R}`