Skip to content
Myr

fix(types): `ToSchema` compatibility (#2605)

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

* feat(types): reduce unnecessary extends check * fix: `ToSchema` backward compat with `I` as `Input['in']` * fix: `ToSchema` backward compat for `R`/`O` argument * chore: denoify

authored by Trung Dang · committed by GitHub · parent d44be95 · Browse files · 2 files+68 added−28 removed
This commit

State

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

Diff stats

2 files+68 added−28 removed

  • other:+68 added−28 removed

2 files+68 added−28 removed

modified:deno_dist/types.ts+34 added-14 removed
4 unmodified lines
5import type { Hono } from './hono.ts'6import type { StatusCode } from './utils/http-status.ts'7import type {8 IfAnyThenEmptyObject,9 IsAny,10 JSONValue,11 Prettify,12 RemoveBlankRecord,13 Simplify,14 UnionToIntersection,15} from './utils/types.ts'1617////////////////////////////////////////
11 unmodified lines
29}3031export type Next = () => Promise<void>3233export type ExtractInput<I extends Input | Input['in']> = I extends Input34 ? unknown extends I['in']35 ? {}36 : I['in']37 : I38export type Input = {39 in?: {}40 out?: {}41 outputFormat?: ResponseFormat
1559 unmodified lines
16011602export type ToSchema<1603 M extends string,1604 P extends string,1598 I extends Input,1599 R extends TypedResponse1605 I extends Input | Input['in'],1606 RorO // Response or Output1607> = Prettify<{1608 [K in P]: {1602 [K2 in M as AddDollar<K2>]: R extends TypedResponse<infer T, infer U, infer F>1603 ? {1604 input: unknown extends I['in'] ? AddParam<{}, P> : AddParam<I['in'], P>1605 output: unknown extends T ? {} : T1606 outputFormat: I extends { outputFormat: string }1607 ? I['outputFormat']1608 : unknown extends F1609 ? never1610 : F1611 status: U1612 }1613 : never1609 [K2 in M as AddDollar<K2>]: Simplify<1610 {1611 input: AddParam<ExtractInput<I>, P>1612 } & (IsAny<RorO> extends true1613 ? {1614 output: {}1615 outputFormat: ResponseFormat1616 status: StatusCode1617 }1618 : RorO extends TypedResponse<infer T, infer U, infer F>1619 ? {1620 output: unknown extends T ? {} : T1621 outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F1622 status: U1623 }1624 : {1625 output: unknown extends RorO ? {} : RorO1626 outputFormat: unknown extends RorO1627 ? 'json'1628 : I extends { outputFormat: string }1629 ? I['outputFormat']1630 : 'json'1631 status: StatusCode1632 })1633 >1634 }1635}>16361637export type Schema = {
200 unmodified lines
modified:src/types.ts+34 added-14 removed
4 unmodified lines
5import type { Hono } from './hono'6import type { StatusCode } from './utils/http-status'7import type {8 IfAnyThenEmptyObject,9 IsAny,10 JSONValue,11 Prettify,12 RemoveBlankRecord,13 Simplify,14 UnionToIntersection,15} from './utils/types'1617////////////////////////////////////////
11 unmodified lines
29}3031export type Next = () => Promise<void>3233export type ExtractInput<I extends Input | Input['in']> = I extends Input34 ? unknown extends I['in']35 ? {}36 : I['in']37 : I38export type Input = {39 in?: {}40 out?: {}41 outputFormat?: ResponseFormat
1559 unmodified lines
16011602export type ToSchema<1603 M extends string,1604 P extends string,1598 I extends Input,1599 R extends TypedResponse1605 I extends Input | Input['in'],1606 RorO // Response or Output1607> = Prettify<{1608 [K in P]: {1602 [K2 in M as AddDollar<K2>]: R extends TypedResponse<infer T, infer U, infer F>1603 ? {1604 input: unknown extends I['in'] ? AddParam<{}, P> : AddParam<I['in'], P>1605 output: unknown extends T ? {} : T1606 outputFormat: I extends { outputFormat: string }1607 ? I['outputFormat']1608 : unknown extends F1609 ? never1610 : F1611 status: U1612 }1613 : never1609 [K2 in M as AddDollar<K2>]: Simplify<1610 {1611 input: AddParam<ExtractInput<I>, P>1612 } & (IsAny<RorO> extends true1613 ? {1614 output: {}1615 outputFormat: ResponseFormat1616 status: StatusCode1617 }1618 : RorO extends TypedResponse<infer T, infer U, infer F>1619 ? {1620 output: unknown extends T ? {} : T1621 outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F1622 status: U1623 }1624 : {1625 output: unknown extends RorO ? {} : RorO1626 outputFormat: unknown extends RorO1627 ? 'json'1628 : I extends { outputFormat: string }1629 ? I['outputFormat']1630 : 'json'1631 status: StatusCode1632 })1633 >1634 }1635}>16361637export type Schema = {
200 unmodified lines