Skip to content

Commit

Permalink
fix: fix events type from any to keyof Events (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu authored Sep 4, 2022
1 parent 7f95005 commit a2551b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/aop-runtime/src/AspectExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AdviceContext, AspectAdvice, IAdvice } from '@eggjs/aop-decorator';
import compose from 'koa-compose';
import type { Middleware } from 'koa-compose';

export class AspectExecutor {
obj: Object;
Expand Down Expand Up @@ -73,7 +74,7 @@ export class AspectExecutor {
const lastCall = () => {
return Reflect.apply(this.originMethod, ctx.that, ctx.args);
};
const functions: Array<Function> = [];
const functions: Array<Middleware<AdviceContext>> = [];
for (const aspectAdvice of this.aspectAdviceList) {
const advice: IAdvice = ctx.that[aspectAdvice.name];
const fn = advice.around;
Expand Down
6 changes: 3 additions & 3 deletions core/eventbus-runtime/src/EventHandlerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventHandler, EventName } from '@eggjs/eventbus-decorator';
import { EventHandler, EventName, Events } from '@eggjs/eventbus-decorator';
import { EggContext } from '@eggjs/tegg-runtime';
import { EggPrototype } from '@eggjs/tegg-metadata';
import { MapUtil } from '@eggjs/tegg-common-util';
Expand All @@ -19,11 +19,11 @@ export class EventHandlerFactory {
return this.handlerProtoMap.has(event);
}

async getHandlers(event: EventName, ctx: EggContext): Promise<Array<EventHandler<any>>> {
async getHandlers(event: EventName, ctx: EggContext): Promise<Array<EventHandler<keyof Events>>> {
const handlerProtos = this.handlerProtoMap.get(event) || [];
const eggObjs = await Promise.all(handlerProtos.map(proto => {
return ctx.getOrCreateEggObject(proto.name, proto, ctx);
}));
return eggObjs.map(t => t.obj as EventHandler<any>);
return eggObjs.map(t => t.obj as EventHandler<keyof Events>);
}
}
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,5 @@
"test-exclude": "^6.0.0",
"ts-node": "^10.1.0",
"typescript": "^4.0.0"
},
"workspaces": [
"core/*",
"plugin/*",
"standalone/*"
]
}
}
}

0 comments on commit a2551b2

Please sign in to comment.