Skip to content
Myr

fix(types): `MergeSchemePath` infers param types correctly (#2152)

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

* fix(types): `MergeSchemePath` infers param types correctly * denoify

authored by Yusuke Wada · committed by GitHub · parent f44c705 · Browse files · 3 files+33 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

3 files+33 added−2 removed

  • tests:+31 added−0 removed
  • other:+2 added−2 removed

3 files+33 added−2 removed

modified:deno_dist/types.ts+1 added-1 removed
1625 unmodified lines
1626 : Path extends `${infer Start}:${infer Param}/${infer Rest}`1627 ? { [K in Param | keyof ExtractParams<`/${Rest}`>]: string }1628 : Path extends `${infer Start}:${infer Param}`1629 ? { [K in Param]: string }1630 : never1630 : {}16311632export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> = {1633 [P in keyof OrigSchema as MergePath<SubPath, P & string>]: {1634 [M in keyof OrigSchema[P]]: OrigSchema[P][M] extends {
137 unmodified lines
modified:src/types.test.ts+31 added
535 unmodified lines
536537 type verify = Expect<Equal<Expected, Actual>>538 })539540 test('MergeSchemePath - with params and the subpath does not have params', () => {541 type Actual = MergeSchemaPath<542 {543 '/': {544 $get: {545 input: {546 param: {547 id: string548 }549 }550 output: {}551 }552 }553 },554 '/something'555 >556 type Expected = {557 '/something': {558 $get: {559 input: {560 param: {561 id: string562 }563 }564 output: {}565 }566 }567 }568 type verify = Expect<Equal<Expected, Actual>>569 })570571 type GetKey<T> = T extends Record<infer K, unknown> ? K : never572573 it('Should remove a slash - `/` + `/`', () => {574 type Sub = ToSchema<'get', '/', {}, {}>
516 unmodified lines
modified:src/types.ts+1 added-1 removed
1625 unmodified lines
1626 : Path extends `${infer Start}:${infer Param}/${infer Rest}`1627 ? { [K in Param | keyof ExtractParams<`/${Rest}`>]: string }1628 : Path extends `${infer Start}:${infer Param}`1629 ? { [K in Param]: string }1630 : never1630 : {}16311632export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> = {1633 [P in keyof OrigSchema as MergePath<SubPath, P & string>]: {1634 [M in keyof OrigSchema[P]]: OrigSchema[P][M] extends {
137 unmodified lines