Skip to content

Commit 390f28e

Browse files
committed
update
1 parent cf083de commit 390f28e

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

packages/native/src/event.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,21 +1076,19 @@ export class FastEvent<
10761076
options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>,
10771077
): FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
10781078

1079-
// 处理 FastEventScope 子类(优先级高,放在前面)
1080-
scope<
1081-
E extends Record<string, any> = Record<string, any>,
1082-
P extends string = string,
1083-
M extends Record<string, any> = Record<string, any>,
1084-
C = Context,
1085-
ScopeObject extends FastEventScope<any, any, any> = FastEventScope<any, any, any>,
1086-
>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject & FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
1079+
// 处理 FastEventScope 子类,自动合并实例的事件类型
1080+
scope<P extends string = string, ScopeObject extends FastEventScope<any, any, any> = FastEventScope<any, any, any>>(
1081+
prefix: P,
1082+
scopeObj: ScopeObject,
1083+
options?: DeepPartial<FastEventScopeOptions<Meta>>,
1084+
): FastEventScopeExtend<AllEvents, P, ScopeObject>;
10871085

1088-
// 处理通用的 Class 实例(排除 FastEventScope)
1086+
// 处理通用的 Class 实例( FastEventScope)
10891087
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, C = Context, ScopeObject extends InstanceType<Class> = InstanceType<Class>>(
10901088
prefix: P,
10911089
scopeObj: ScopeObject,
10921090
options?: DeepPartial<FastEventScopeOptions<Meta>>,
1093-
): FastEventScopeExtend<AllEvents, P, ScopeObject>;
1091+
): FastEventScope<ScopeEvents<AllEvents, P>> & ScopeObject;
10941092
scope() {
10951093
const [prefix, scopeObj, options] = parseScopeArgs(arguments, this.options.meta, this.options.context);
10961094
let scope;

packages/native/src/scope.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export class FastEventScope<
356356
prefix: P,
357357
scopeObj: ScopeObject,
358358
options?: DeepPartial<FastEventScopeOptions<Meta>>,
359-
): FastEventScopeExtend<Events, P, ScopeObject>;
359+
): FastEventScope<ScopeEvents<Events, P> & E> & ScopeObject;
360360
scope<
361361
E extends Record<string, any> = Record<string, any>,
362362
P extends string = string,
@@ -387,5 +387,17 @@ export class FastEventScope<
387387
onMessage(message: TypedFastEventMessage<Events, FinalMeta>, args: FastEventListenerArgs<FinalMeta>) {}
388388
}
389389

390-
export type FastEventScopeExtend<Events extends Record<string, any>, Prefix extends string, T extends InstanceType<Class> = never> = FastEventScope<ScopeEvents<Events, Prefix>> &
391-
T;
390+
// 从 FastEventScope 实例中提取事件类型
391+
type ExtractScopeEvents<T> = T extends FastEventScope<infer Events, any, any> ? Events : Record<string, any>;
392+
393+
// 从 FastEventScope 实例中提取 Meta 类型
394+
type ExtractScopeMeta<T> = T extends FastEventScope<any, infer Meta, any> ? Meta : Record<string, any>;
395+
396+
// 从 FastEventScope 实例中提取 Context 类型
397+
type ExtractScopeContext<T> = T extends FastEventScope<any, any, infer Context> ? Context : never;
398+
399+
export type FastEventScopeExtend<
400+
Events extends Record<string, any>,
401+
Prefix extends string,
402+
T extends FastEventScope<any, any, any> = FastEventScope<any, any, any>,
403+
> = FastEventScope<ScopeEvents<Events, Prefix> & ExtractScopeEvents<T>, ExtractScopeMeta<T>, ExtractScopeContext<T>> & T;

0 commit comments

Comments
 (0)