Skip to content

Commit 1463b7e

Browse files
committed
fix: 修复当emit消息时,meta参数约束不是可选导致提示类型错误
1 parent a0b1fc7 commit 1463b7e

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

packages/native/src/__tests__/types/meta.types.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ describe("FastEvent元数据类型检查", () => {
1717
b: string
1818
c: boolean
1919
}
20+
test("未指定元数据类型", () => {
21+
const emitter = new FastEvent()
22+
type cases = [
23+
Expect<Equal<typeof emitter.options.meta, Record<string, any>>>
24+
]
25+
emitter.on("x", (message) => {
26+
type cases = [
27+
Expect<Equal<typeof message.meta, FastEventMeta & Record<string, any>>>
28+
]
29+
})
30+
emitter.once("x", (message) => {
31+
type cases = [
32+
Expect<Equal<typeof message.meta, FastEventMeta & Record<string, any>>>
33+
]
34+
})
35+
36+
emitter.onAny((message) => {
37+
type cases = [
38+
Expect<Equal<typeof message.meta, FastEventMeta & Record<string, any>>>
39+
]
40+
})
41+
})
42+
2043
test("全局元数据类型", () => {
2144
const emitter = new FastEvent<CustomEvents, CustomMeta>()
2245
type cases = [

packages/native/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export type FastEventEmitMessage<
3232
[K in keyof Events]: {
3333
type: Exclude<K, number | symbol>
3434
payload?: Events[K]
35-
meta?: Partial<FastEventMeta> & M & Record<string, any>
35+
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>
3636
}
3737
}[Exclude<keyof Events, number | symbol>]
3838
) & FaseEventMessageExtends
@@ -162,7 +162,7 @@ export type FastEventListenOptions<
162162

163163
export type FastEventListenerArgs<M = Record<string, any>> = {
164164
retain?: boolean;
165-
meta?: Partial<M> & Record<string, any>;
165+
meta?: DeepPartial<M> & Record<string, any>;
166166
abortSignal?: AbortSignal; // 用于传递给监听器函数
167167
/**
168168
*

0 commit comments

Comments
 (0)