Skip to content

chore: improve readability of query/param/header types #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions packages/io-ts-http/src/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,17 @@ type EmitOutputTypeErrors<
: {
[K in keyof P & string]: P[K] extends t.Type<any, O, any>
? P[K]
: `Codec's output type is not assignable to ${OName}. Try using one like \`NumberFromString\``;
: `Codec's output type is not assignable to \`${OName}\`. Try using one like \`NumberFromString\``;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion seems like a blind guess 😅

I don't suppose there's any way to test these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah didn't really want to get into some long conditional chain of P[K] extends t.NumberC ? 'NumberFromString' : ... many other codecs

As for testing I briefly thought of that and it's definitely not as easy as a "check that an expression typechecks" test, since we don't want to break compilation.

};

type QueryValue = string | string[] | undefined;
type ParamValue = string | undefined;
type HeaderValue = string | undefined;

type EmitPropsErrors<P extends HttpRequestCombinatorProps> = {
params?: EmitOutputTypeErrors<P['params'], string | undefined, 'string | undefined'>;
query?: EmitOutputTypeErrors<
P['query'],
string | string[] | undefined,
'string | string[] | undefined'
>;
headers?: EmitOutputTypeErrors<
P['headers'],
string | undefined,
'string | undefined'
>;
params?: EmitOutputTypeErrors<P['params'], ParamValue, 'string | undefined'>;
query?: EmitOutputTypeErrors<P['query'], QueryValue, 'string | string[] | undefined'>;
headers?: EmitOutputTypeErrors<P['headers'], HeaderValue, 'string | undefined'>;
};

export function httpRequest<
Expand Down