Skip to content
Myr

fix(types): fix `MergeSchemaPath` correct (#1426)

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

* fix(types): fix `MergeSchemaPath` correct * denoify

authored by Yusuke Wada · committed by GitHub · parent 2d5b8e6 · Browse files · 4 files+23 added−3 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+23 added−3 removed

  • tests:+21 added−1 removed
  • other:+2 added−2 removed

4 files+23 added−3 removed

modified:deno_dist/types.ts+1 added-1 removed
350 unmodified lines
351 }352}353354export type MergeSchemaPath<OrigSchema, SubPath extends string> = {355 [K in keyof OrigSchema as `${SubPath}${K & string}`]: OrigSchema[K]355 [K in keyof OrigSchema as `${MergePath<SubPath, K & string>}`]: OrigSchema[K]356}357358export type AddParam<I, P extends string> = ParamKeys<P> extends never359 ? I
120 unmodified lines
modified:src/client/client.test.ts+1 added-1 removed
384 unmodified lines
385 const book = new Hono().get('/', (c) => c.jsonT({ ok: true }))386 const app = new Hono().basePath('/v1').route('/book', book)387 type AppType = typeof app388 const client = hc<AppType>('http://localhost')389 const res = await client.v1.book.index.$get()389 const res = await client.v1.book.$get()390 const data = await res.json()391 type verify = Expect<Equal<boolean, typeof data.ok>>392 expect(data.ok).toBe(true)393 })
75 unmodified lines
modified:src/types.test.ts+20 added
514 unmodified lines
515 }516517 type verify = Expect<Equal<Expected, Actual>>518 })519520 type GetKey<T> = T extends Record<infer K, unknown> ? K : never521522 it('Should remove a slash - `/` + `/`', () => {523 type Sub = ToSchema<'get', '/', {}, {}>524 type Actual = MergeSchemaPath<Sub, '/'>525 type verify = Expect<Equal<'/', GetKey<Actual>>>526 })527528 it('Should remove a slash - `/tags` + `/`', () => {529 type Sub = ToSchema<'get', '/tags', {}, {}>530 type Actual = MergeSchemaPath<Sub, '/'>531 type verify = Expect<Equal<'/tags', GetKey<Actual>>>532 })533534 it('Should remove a slash - `/` + `/tags`', () => {535 type Sub = ToSchema<'get', '/', {}, {}>536 type Actual = MergeSchemaPath<Sub, '/tags'>537 type verify = Expect<Equal<'/tags', GetKey<Actual>>>538 })539})540541describe('Different types using jsonT()', () => {542 describe('no path pattern', () => {
98 unmodified lines
modified:src/types.ts+1 added-1 removed
350 unmodified lines
351 }352}353354export type MergeSchemaPath<OrigSchema, SubPath extends string> = {355 [K in keyof OrigSchema as `${SubPath}${K & string}`]: OrigSchema[K]355 [K in keyof OrigSchema as `${MergePath<SubPath, K & string>}`]: OrigSchema[K]356}357358export type AddParam<I, P extends string> = ParamKeys<P> extends never359 ? I
120 unmodified lines