@@ -5,7 +5,7 @@ import { Logger } from '@rocket.chat/logger';
55import { Users } from '@rocket.chat/models' ;
66import { Random } from '@rocket.chat/random' ;
77import type { JoinPathPattern , Method } from '@rocket.chat/rest-typings' ;
8- import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv ' ;
8+ import { ajv } from '@rocket.chat/rest-typings' ;
99import { wrapExceptions } from '@rocket.chat/tools' ;
1010import type { ValidateFunction } from 'ajv' ;
1111import { Accounts } from 'meteor/accounts-base' ;
@@ -66,8 +66,13 @@ export type Prettify<T> = {
6666
6767type ExtractValidation < T > = T extends ValidateFunction < infer TSchema > ? TSchema : never ;
6868
69- export type ExtractRoutesFromAPI < T > =
70- T extends APIClass < any , infer TOperations > ? ( TOperations extends MinimalRoute ? Prettify < ConvertToRoute < TOperations > > : never ) : never ;
69+ type UnionToIntersection < U > = ( U extends any ? ( x : U ) => any : never ) extends ( x : infer I ) => any ? I : never ;
70+
71+ export type ExtractRoutesFromAPI < T > = Prettify <
72+ UnionToIntersection <
73+ T extends APIClass < any , infer TOperations > ? ( TOperations extends MinimalRoute ? Prettify < ConvertToRoute < TOperations > > : never ) : never
74+ >
75+ > ;
7176
7277type ConvertToRoute < TRoute extends MinimalRoute > = {
7378 [ K in TRoute [ 'path' ] ] : {
@@ -578,7 +583,7 @@ export class APIClass<
578583 TSubPathPattern extends string ,
579584 TOptions extends TypedOptions ,
580585 TPathPattern extends `${TBasePath } /${TSubPathPattern } `,
581- > ( method : Method , subpath : TSubPathPattern , options : TOptions ) : void {
586+ > ( method : MinimalRoute [ 'method' ] , subpath : TSubPathPattern , options : TOptions ) : void {
582587 const path = `/${ this . apiPath } /${ subpath } ` . replaceAll ( '//' , '/' ) as TPathPattern ;
583588 this . typedRoutes = this . typedRoutes || { } ;
584589 this . typedRoutes [ path ] = this . typedRoutes [ subpath ] || { } ;
@@ -629,7 +634,7 @@ export class APIClass<
629634 }
630635
631636 private method < TSubPathPattern extends string , TOptions extends TypedOptions , TPathPattern extends `${TBasePath } /${TSubPathPattern } `> (
632- method : Method ,
637+ method : MinimalRoute [ 'method' ] ,
633638 subpath : TSubPathPattern ,
634639 options : TOptions ,
635640 action : TypedAction < TOptions , TSubPathPattern > ,
0 commit comments