submessage: Fix implicit use of any.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-05-03 18:25:26 -07:00
committed by Tim Abbott
parent a53fe206ea
commit 819bccfec1
2 changed files with 10 additions and 9 deletions

View File

@@ -30,16 +30,11 @@ export type WidgetData = {
question: string;
};
export type InboundData = Record<string, unknown> & {type: string};
export type InboundData = unknown;
export type NewOptionOutboundData = {type: string; idx: number; option: string};
export type QuestionOutboundData = {type: string; question: string};
export type VoteOutboundData = {type: string; key: string; vote: number};
export type PollHandle = {
// Add generic key property to allow string indexing on PollHandle type in `handle_event` method.
[key: string]: {
outbound: (arg: string) => InboundData | undefined;
inbound: (sender_id: number, data: InboundData) => void;
};
new_option: {
outbound: (option: string) => NewOptionOutboundData;
inbound: (sender_id: number | string, data: InboundData) => void;
@@ -294,8 +289,14 @@ export class PollData {
}
handle_event(sender_id: number, data: InboundData): void {
assert(
typeof data === "object" &&
data !== null &&
"type" in data &&
typeof data.type === "string",
);
const type = data.type;
if (this.handle[type]) {
if (type === "new_option" || type === "question" || type === "vote") {
this.handle[type].inbound(sender_id, data);
} else {
this.report_error_function(`poll widget: unknown inbound type: ${type}`);