windingwind / zotero-types

TypeScript definitions for Zotero.
https://www.npmjs.com/package/zotero-types
MIT License
56 stars 9 forks source link

Add _ZoteroTypes.Notifier.ExtraData and fix pdfjs-dist version #37

Closed northword closed 9 months ago

volatile-static commented 9 months ago

关于notify的类型标注,我计划利用泛型来囊括目前源码中的所有情况

windingwind commented 9 months ago

我觉得试试看type先,尽量少去封装,封装多了维护成本变高

volatile-static commented 9 months ago

我觉得维护这个类型并不比维护一个wrapper简单多少,而且放toolkit的好处是省一个unregister。而且这个类型非常复杂,我暂时想不到什么好办法。pdfjs的版本我先commit一下。

volatile-static commented 9 months ago

如果后续没有其他办法、要维持原状的话,我再reopen这个PR然后合并

volatile-static commented 9 months ago

Zotero_Notifiertq.zip 这是完整搜索结果和GPT生成的定义:

// 基础事件接口
interface NotifierEvent {
    event: string;
}

// 定义特定事件的接口
interface TabEvent extends NotifierEvent {
    ids: string[];
    data: { [key: string]: any };
}

interface ItemEvent extends NotifierEvent {
    ids: number[];
    data?: { [key: number]: any };
}

interface FileEvent extends NotifierEvent {
    id: number;
}

interface CollectionEvent extends NotifierEvent {
    id: number;
}

interface GroupEvent extends NotifierEvent {
    id: number;
}

interface FeedEvent extends NotifierEvent {
    id: number;
}

interface SearchEvent extends NotifierEvent {
    id: number;
}

interface TagEvent extends NotifierEvent {
    ids: number[];
}

interface SettingEvent extends NotifierEvent {
    ids: number[];
}

// ... 其他特定事件接口

// 事件类型映射
interface NotifierEventMap {
    "tab": TabEvent;
    "item": ItemEvent;
    "file": FileEvent;
    "collection": CollectionEvent;
    "group": GroupEvent;
    "feed": FeedEvent;
    "search": SearchEvent;
    "tag": TagEvent;
    "setting": SettingEvent;
    // ... 其他事件映射
}

// 重载trigger和queue函数
declare module "Zotero" {
    function trigger<K extends keyof NotifierEventMap>(type: K, event: NotifierEventMap[K]): void;
    function queue<K extends keyof NotifierEventMap>(type: K, event: NotifierEventMap[K]): void;
}