报错:ts2769
原因:mitt3.0进行了更新
源代码:
js
import mitt from 'mitt'
export const bus = mitt()
更正代码:
ts
import mitt from 'mitt'
import type {Emitter} from 'mitt'
export const bus:Emitter<any> = mitt()
可对any进行限制,如下所示:
ts
import mitt, { Emitter } from 'mitt';
type Events = {
foo: string;
bar?: number;
};
const emitter: Emitter<Events> = mitt<Events>();