Skip to content

Commit

Permalink
Put typehints on overridden functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr committed Nov 7, 2024
1 parent b6f8d14 commit 156d29a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import {
ISendEventToWidgetActionRequest,
ISendToDeviceToWidgetActionRequest,
ISendEventFromWidgetResponseData,
IWidgetApiRequestData,
WidgetApiAction,
IWidgetApiResponse,
IWidgetApiResponseData,
} from "matrix-widget-api";

import { MatrixEvent, IEvent, IContent, EventStatus } from "./models/event.ts";
Expand Down Expand Up @@ -150,20 +154,24 @@ export class RoomWidgetClient extends MatrixClient {
super(opts);

const transportSend = this.widgetApi.transport.send.bind(this.widgetApi.transport);
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
this.widgetApi.transport.send = async (action, data) => {
this.widgetApi.transport.send = async <T extends IWidgetApiRequestData, R extends IWidgetApiResponseData = IWidgetApiAcknowledgeResponseData>(
action: WidgetApiAction,
data: T,
): Promise<R> => {
try {
return await transportSend(action, data);
return await transportSend<T, R>(action, data);
} catch (error) {
processAndThrow(error);
}
};

const transportSendComplete = this.widgetApi.transport.sendComplete.bind(this.widgetApi.transport);
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
this.widgetApi.transport.sendComplete = async (action, data) => {
this.widgetApi.transport.sendComplete = async <T extends IWidgetApiRequestData, R extends IWidgetApiResponse>(
action: WidgetApiAction,
data: T,
): Promise<R> => {
try {
return await transportSendComplete(action, data);
return await transportSendComplete<T, R>(action, data);
} catch (error) {
processAndThrow(error);
}
Expand Down

0 comments on commit 156d29a

Please sign in to comment.