Skip to content
Myr

fix(types): `MergePath` merge blank paths correctly (#2365)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(types): `MergePath` merge blank paths correctly * denoify

authored by Yusuke Wada · committed by GitHub · parent f60ab8b · Browse files · 4 files+35 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+35 added−2 removed

  • tests:+29 added−0 removed
  • other:+6 added−2 removed

4 files+35 added−2 removed

modified:deno_dist/types.ts+3 added-1 removed
1647 unmodified lines
1648 : I & { param: UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>> }16491650type AddDollar<T extends string> = `$${Lowercase<T>}`16511652export type MergePath<A extends string, B extends string> = A extends ''1652export type MergePath<A extends string, B extends string> = B extends ''1653 ? MergePath<A, '/'>1654 : A extends ''1655 ? B1656 : A extends '/'1657 ? B1658 : A extends `${infer P}/`
115 unmodified lines
modified:src/client/client.test.ts+21 added
498 unmodified lines
499 const url = client.api.bar.$url()500 expect(url.href).toBe('http://localhost/api/bar')501 })502 })503504 describe('With a blank path', () => {505 const app = new Hono().basePath('/api/v1')506 const routes = app.route(507 '/me',508 new Hono().route(509 '',510 new Hono().get('', async (c) => {511 return c.json({ name: 'hono' })512 })513 )514 )515 const client = hc<typeof routes>('http://localhost')516517 it('Should infer paths correctly', async () => {518 // Should not a throw type error519 const url = client.api.v1.me.$url()520 expectTypeOf<URL>(url)521 expect(url.href).toBe('http://localhost/api/v1/me')522 })523 })524})525526describe('Use custom fetch method', () => {527 it('Should call the custom fetch method when provided', async () => {
97 unmodified lines
modified:src/types.test.ts+8 added
533 unmodified lines
534 type path3 = MergePath<'/api/', '/'>535 type verify3 = Expect<Equal<'/api/', path3>>536 type path4 = MergePath<'/api', '/'>537 type verify4 = Expect<Equal<'/api', path4>>538 type path5 = MergePath<'/', ''>539 type verify5 = Expect<Equal<'/', path5>>540 type path6 = MergePath<'', '/'>541 type verify6 = Expect<Equal<'/', path6>>542 type path7 = MergePath<'/', '/'>543 type verify7 = Expect<Equal<'/', path7>>544 type path8 = MergePath<'', ''>545 type verify8 = Expect<Equal<'/', path8>>546 })547})548549describe('MergeSchemaPath', () => {
913 unmodified lines
modified:src/types.ts+3 added-1 removed
1647 unmodified lines
1648 : I & { param: UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>> }16491650type AddDollar<T extends string> = `$${Lowercase<T>}`16511652export type MergePath<A extends string, B extends string> = A extends ''1652export type MergePath<A extends string, B extends string> = B extends ''1653 ? MergePath<A, '/'>1654 : A extends ''1655 ? B1656 : A extends '/'1657 ? B1658 : A extends `${infer P}/`
115 unmodified lines