Skip to content

Commit

Permalink
fix(client): set Path as the default of Original (#3058)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-shaka committed Jun 29, 2024
1 parent 2d3bc55 commit 1d16b84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/client/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
2 changes: 1 addition & 1 deletion src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down

0 comments on commit 1d16b84

Please sign in to comment.