From a0c51b3c3ad549a8ec531533056630e1ddd44ca9 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Tue, 9 May 2023 11:57:49 +0200 Subject: [PATCH] fix: jsonrpc: typescript client: fix types of events in event emitter (#4373) * fix: jsonrpc: typescript client: fix types of events in event emitter * add ts ignore to remove ts error (when building in ts5) doing the types right via casting is to complicated IMO and has no real benefit here. --- CHANGELOG.md | 3 ++ deltachat-jsonrpc/typescript/src/client.ts | 34 ++++++++++------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f8ef02c..e4980a1f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,13 @@ - BREAKING: jsonrpc: - `get_chatlist_items_by_entries` now takes only chatids instead of `ChatListEntries` - `get_chatlist_entries` now returns `Vec` of chatids instead of `ChatListEntries` + - `Event`: `context_id` property is now called `contextId` - JSON-RPC: add API to get reactions outside the message snapshot ### Fixes - Make the bots automatically accept group chat contact requests. #4377 +### Fixes +- jsonrpc: typescript client: fix types of events in event emitter ## [1.114.0] - 2023-04-24 diff --git a/deltachat-jsonrpc/typescript/src/client.ts b/deltachat-jsonrpc/typescript/src/client.ts index d2065cba3..1a51b5e04 100644 --- a/deltachat-jsonrpc/typescript/src/client.ts +++ b/deltachat-jsonrpc/typescript/src/client.ts @@ -1,33 +1,28 @@ import * as T from "../generated/types.js"; +import { EventType } from "../generated/types.js"; import * as RPC from "../generated/jsonrpc.js"; import { RawClient } from "../generated/client.js"; import { WebsocketTransport, BaseTransport, Request } from "yerpc"; import { TinyEmitter } from "@deltachat/tiny-emitter"; -type DCWireEvent = { - event: T; - contextId: number; -}; -// export type Events = Record< -// Event["type"] | "ALL", -// (event: DeltaChatEvent) => void -// >; - -type Events = { ALL: (accountId: number, event: Event) => void } & { - [Property in Event["type"]]: ( +type Events = { ALL: (accountId: number, event: EventType) => void } & { + [Property in EventType["type"]]: ( accountId: number, - event: Extract + event: Extract ) => void; }; -type ContextEvents = { ALL: (event: Event) => void } & { - [Property in Event["type"]]: ( - event: Extract +type ContextEvents = { ALL: (event: EventType) => void } & { + [Property in EventType["type"]]: ( + event: Extract ) => void; }; -export type DcEvent = Event; -export type DcEventType = Extract; +export type DcEvent = EventType; +export type DcEventType = Extract< + EventType, + { type: T } +>; export class BaseDeltaChat< Transport extends BaseTransport @@ -50,8 +45,9 @@ export class BaseDeltaChat< async eventLoop(): Promise { while (true) { const event = await this.rpc.getNextEvent(); - this.emit(event.event.type, event.contextId, event.event as any); - this.emit("ALL", event.contextId, event.event as any); + //@ts-ignore + this.emit(event.event.type, event.contextId, event.event); + this.emit("ALL", event.contextId, event.event); if (this.contextEmitters[event.contextId]) { this.contextEmitters[event.contextId].emit(