Skip to content

Commit cac1463

Browse files
refactor: update ExtractValidation type to use 'unknown' (#36318)
1 parent 512586a commit cac1463

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

apps/meteor/app/api/server/ApiClass.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ it('Should return the expected type', () => {
3939
>;
4040
true as test;
4141
});
42+
43+
describe('ExtractRoutesFromAPI', () => {
44+
it('Should extract correct function signature when query is not present', () => {
45+
type APIWithNeverQuery = APIClass<
46+
'/v1',
47+
{
48+
method: 'GET';
49+
path: '/v1/endpoint.test';
50+
response: {
51+
200: ValidateFunction<unknown>;
52+
};
53+
authRequired: true;
54+
}
55+
>;
56+
type ExpectedFunctionSignature = Expect<
57+
ShallowEqual<ExtractRoutesFromAPI<APIWithNeverQuery>['/v1/endpoint.test']['GET'], () => unknown>
58+
>;
59+
true as ExpectedFunctionSignature;
60+
});
61+
});

apps/meteor/app/api/server/ApiClass.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ type ConvertToRoute<TRoute extends MinimalRoute> = {
7373
[K in TRoute['path']]: {
7474
[K2 in Extract<TRoute, { path: K }>['method']]: K2 extends 'GET'
7575
? (
76-
params: ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>,
76+
...args: [ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>] extends [never]
77+
? [params?: never]
78+
: [params: ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['query']>]
7779
) => ExtractValidation<Extract<TRoute, { path: K; method: K2 }>['response'][200]>
7880
: K2 extends 'POST'
7981
? (

0 commit comments

Comments
 (0)