Skip to content
Myr

perf(types): reduce `Simplify` in `ToSchema` (#4597)

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

* perf(types): reduce `Simplify` in `ToSchema` * ci: apply automated fixes ---------

authored by Yusuke Wada · committed by GitHub · parent 41ee1bb · Browse files · 1 file+28 added−28 removed
This commit

State

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

Trailers

  • Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

Diff stats

1 file+28 added−28 removed

  • other:+28 added−28 removed

1 file+28 added−28 removed

modified:src/types.ts+28 added-28 removed
2189 unmodified lines
2190////// ToSchema //////2191////// //////2192////////////////////////////////////////21932194type ToSchemaOutput<RorO, I extends Input | Input['in']> =2195 RorO extends TypedResponse<infer T, infer U, infer F>2196 ? {2197 output: unknown extends T ? {} : T2198 outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F2199 status: U2200 }2201 : {2202 output: unknown extends RorO ? {} : RorO2203 outputFormat: unknown extends RorO2204 ? 'json'2205 : I extends { outputFormat: string }2206 ? I['outputFormat']2207 : 'json'2208 status: StatusCode2209 }22102211export type ToSchema<2212 M extends string,2213 P extends string,2214 I extends Input | Input['in'],2215 RorO, // Response or Output2216> =2217 IsAny<RorO> extends true2201 ? Simplify<{2218 ? {2219 [K in P]: {2203 [K2 in M as AddDollar<K2>]: Simplify<2204 {2205 input: AddParam<ExtractInput<I>, P>2206 } & {2207 output: {}2208 outputFormat: ResponseFormat2209 status: StatusCode2210 }2220 [K2 in M as AddDollar<K2>]: {2221 input: AddParam<ExtractInput<I>, P>2222 output: {}2223 outputFormat: ResponseFormat2224 status: StatusCode2225 }2211 >2226 }2213 }>2227 }2228 : [RorO] extends [never]2229 ? {}2230 : [RorO] extends [Promise<void>]2231 ? {}2218 : Simplify<{2232 : {2233 [K in P]: {2234 [K2 in M as AddDollar<K2>]: Simplify<2235 {2236 input: AddParam<ExtractInput<I>, P>2223 } & (RorO extends TypedResponse<infer T, infer U, infer F>2224 ? {2225 output: unknown extends T ? {} : T2226 outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F2227 status: U2228 }2229 : {2230 output: unknown extends RorO ? {} : RorO2231 outputFormat: unknown extends RorO2232 ? 'json'2233 : I extends { outputFormat: string }2234 ? I['outputFormat']2235 : 'json'2236 status: StatusCode2237 })2237 } & ToSchemaOutput<RorO, I>2238 >2239 }2240 }>2240 }22412242export type Schema = {2243 [Path: string]: {2244 [Method: `$${Lowercase<string>}`]: Endpoint
242 unmodified lines