Skip to content
Merged
Show file tree
Hide file tree
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: 20 additions & 0 deletions apps/meteor/app/api/server/ApiClass.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ it('Should return the expected type', () => {
>;
true as test;
});

describe('ExtractRoutesFromAPI', () => {
it('Should extract correct function signature when query is not present', () => {
type APIWithNeverQuery = APIClass<
'/v1',
{
method: 'GET';
path: '/v1/endpoint.test';
response: {
200: ValidateFunction<unknown>;
};
authRequired: true;
}
>;
type ExpectedFunctionSignature = Expect<
ShallowEqual<ExtractRoutesFromAPI<APIWithNeverQuery>['/v1/endpoint.test']['GET'], () => unknown>
>;
true as ExpectedFunctionSignature;
});
});
4 changes: 3 additions & 1 deletion apps/meteor/app/api/server/ApiClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ type ConvertToRoute<TRoute extends MinimalRoute> = {
[K in TRoute['path']]: {
[K2 in Extract<TRoute, { path: K }>['method']]: K2 extends 'GET'
? (
params: ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>,
...args: [ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>] extends [never]
? [params?: never]
: [params: ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>]
) => ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['response'][200]>
: K2 extends 'POST'
? (
Expand Down
Loading