File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ import * as t from 'io-ts';
22
33import { Status } from '@api-ts/response' ;
44
5- export type HttpResponse = t . Props ;
5+ export type HttpResponse = {
6+ [ K : string ] : t . Mixed ;
7+ } ;
68
7- export type KnownResponses < Response extends HttpResponse > = {
8- [ K in keyof Response ] : K extends Status ? K : never ;
9- } [ keyof Response ] ;
9+ type KnownResponses < Response extends HttpResponse > = {
10+ [ K in Status ] : K extends keyof Response ? K : never ;
11+ } [ Status ] ;
1012
1113export const HttpResponseCodes : { [ K in Status ] : number } = {
1214 ok : 200 ,
Original file line number Diff line number Diff line change 11import * as t from 'io-ts' ;
22
3- import { HttpResponse , KnownResponses } from './httpResponse' ;
3+ import { HttpResponse } from './httpResponse' ;
44import { HttpRequestCodec } from './httpRequest' ;
5+ import { Status } from '@api-ts/response' ;
56
67export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' ;
78
@@ -14,11 +15,13 @@ export type HttpRoute = {
1415
1516export type RequestType < T extends HttpRoute > = t . TypeOf < T [ 'request' ] > ;
1617export type ResponseType < T extends HttpRoute > = {
17- [ K in KnownResponses < T [ 'response' ] > ] : {
18- type : K ;
19- payload : t . TypeOf < T [ 'response' ] [ K ] > ;
20- } ;
21- } [ KnownResponses < T [ 'response' ] > ] ;
18+ [ K in Status ] : K extends keyof T [ 'response' ]
19+ ? {
20+ type : K ;
21+ payload : t . TypeOf < T [ 'response' ] [ K ] > ;
22+ }
23+ : never ;
24+ } [ Status ] ;
2225
2326export type ApiSpec = {
2427 [ Key : string ] : {
You can’t perform that action at this time.
0 commit comments