Skip to content

Commit a3d75fa

Browse files
authored
fix: Resolve some type problems (#2260)
1 parent 2fb4cfa commit a3d75fa

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

packages/express/src/declarations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import {
66
} from '@feathersjs/feathers';
77

88
interface ExpressUseHandler<T, ServiceTypes> {
9-
<L extends keyof ServiceTypes> (
10-
path: ServiceTypes[L] extends never ? string|RegExp : L,
9+
<L extends keyof ServiceTypes & string> (
10+
path: L,
1111
...middlewareOrService: (
1212
Express|express.RequestHandler|
13-
(ServiceTypes[L] extends never ? ServiceInterface<any> : ServiceTypes[L])
13+
(keyof any extends keyof ServiceTypes ? ServiceInterface<any> : ServiceTypes[L])
1414
)[]
1515
): T;
16+
(path: RegExp, ...expressHandlers: express.RequestHandler[]): T;
1617
(...expressHandlers: express.RequestHandler[]): T;
1718
(handler: Express|express.ErrorRequestHandler): T;
1819
}

packages/express/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export * from './declarations';
2121

2222
const debug = Debug('@feathersjs/express');
2323

24-
export default function feathersExpress<S = any, C = any> (feathersApp?: FeathersApplication, expressApp: Express = express()): Application<S, C> {
24+
export default function feathersExpress<S = any, C = any> (feathersApp?: FeathersApplication<S, C>, expressApp: Express = express()): Application<S, C> {
2525
if (!feathersApp) {
2626
return expressApp as any;
2727
}
@@ -62,7 +62,7 @@ export default function feathersExpress<S = any, C = any> (feathersApp?: Feather
6262

6363
debug('Registering service with middleware', middleware);
6464
// Since this is a service, call Feathers `.use`
65-
feathersApp.use.call(this, location, service, { middleware });
65+
(feathersApp as FeathersApplication).use.call(this, location, service, { middleware });
6666

6767
return this;
6868
},

packages/feathers/src/application.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ export class Feathers<ServiceTypes, AppSettings> extends EventEmitter implements
7575

7676
use<L extends keyof ServiceTypes & string> (
7777
path: L,
78-
service: (keyof any extends keyof ServiceTypes ? ServiceInterface<any> : ServiceTypes[L]) | Application,
78+
service: keyof any extends keyof ServiceTypes ? ServiceInterface<any> | Application : ServiceTypes[L],
7979
options?: ServiceOptions
8080
): this {
8181
if (typeof path !== 'string') {
8282
throw new Error(`'${path}' is not a valid service path.`);
8383
}
8484

8585
const location = (stripSlashes(path) || '/') as L;
86-
const subApp = service as FeathersApplication;
86+
const subApp = service as Application;
8787
const isSubApp = typeof subApp.service === 'function' && subApp.services;
8888

8989
if (isSubApp) {
@@ -113,15 +113,15 @@ export class Feathers<ServiceTypes, AppSettings> extends EventEmitter implements
113113
return this;
114114
}
115115

116-
hooks (hookMap: HookOptions<Application<ServiceTypes, AppSettings>, any>) {
116+
hooks (hookMap: HookOptions<this, any>) {
117117
const legacyMap = hookMap as LegacyHookMap<this, any>;
118118

119119
if (legacyMap.before || legacyMap.after || legacyMap.error) {
120120
return this.legacyHooks(legacyMap);
121121
}
122122

123123
if (Array.isArray(hookMap)) {
124-
this.appHooks[HOOKS].push(...hookMap);
124+
this.appHooks[HOOKS].push(...hookMap as any);
125125
} else {
126126
const methodHookMap = hookMap as HookMap<Application<ServiceTypes, AppSettings>, any>;
127127

packages/feathers/src/declarations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
183183
*/
184184
use<L extends keyof ServiceTypes & string> (
185185
path: L,
186-
service: (keyof any extends keyof ServiceTypes ? ServiceInterface<any> : ServiceTypes[L]) | Application,
186+
service: keyof any extends keyof ServiceTypes ? ServiceInterface<any> | Application : ServiceTypes[L],
187187
options?: ServiceOptions
188188
): this;
189189

@@ -205,7 +205,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
205205
*
206206
* @param map The application hook settings.
207207
*/
208-
hooks (map: HookOptions<Application<ServiceTypes, AppSettings>, any>): this;
208+
hooks (map: HookOptions<this, any>): this;
209209
}
210210

211211
// This needs to be an interface instead of a type
@@ -309,7 +309,7 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
309309

310310
// Legacy hook typings
311311
export type LegacyHookFunction<A = Application, S = Service<any, any>> =
312-
(this: S, context: HookContext<A, S>) => (Promise<HookContext<A, S> | void> | HookContext<A, S> | void);
312+
(this: S, context: HookContext<A, S>) => (Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void);
313313

314314
type LegacyHookMethodMap<A, S> =
315315
{ [L in keyof S]?: SelfOrArray<LegacyHookFunction<A, S>>; } &

0 commit comments

Comments
 (0)