mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	submessage: Fix implicit use of any.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							a53fe206ea
						
					
				
				
					commit
					819bccfec1
				
			@@ -30,16 +30,11 @@ export type WidgetData = {
 | 
				
			|||||||
    question: string;
 | 
					    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 NewOptionOutboundData = {type: string; idx: number; option: string};
 | 
				
			||||||
export type QuestionOutboundData = {type: string; question: string};
 | 
					export type QuestionOutboundData = {type: string; question: string};
 | 
				
			||||||
export type VoteOutboundData = {type: string; key: string; vote: number};
 | 
					export type VoteOutboundData = {type: string; key: string; vote: number};
 | 
				
			||||||
export type PollHandle = {
 | 
					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: {
 | 
					    new_option: {
 | 
				
			||||||
        outbound: (option: string) => NewOptionOutboundData;
 | 
					        outbound: (option: string) => NewOptionOutboundData;
 | 
				
			||||||
        inbound: (sender_id: number | string, data: InboundData) => void;
 | 
					        inbound: (sender_id: number | string, data: InboundData) => void;
 | 
				
			||||||
@@ -294,8 +289,14 @@ export class PollData {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    handle_event(sender_id: number, data: InboundData): void {
 | 
					    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;
 | 
					        const type = data.type;
 | 
				
			||||||
        if (this.handle[type]) {
 | 
					        if (type === "new_option" || type === "question" || type === "vote") {
 | 
				
			||||||
            this.handle[type].inbound(sender_id, data);
 | 
					            this.handle[type].inbound(sender_id, data);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.report_error_function(`poll widget: unknown inbound type: ${type}`);
 | 
					            this.report_error_function(`poll widget: unknown inbound type: ${type}`);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,7 +79,7 @@ export function get_message_events(message: Message): SubmessageEvents | undefin
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    message.submessages.sort((m1, m2) => m1.id - m2.id);
 | 
					    message.submessages.sort((m1, m2) => m1.id - m2.id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const events = message.submessages.map((obj) => ({
 | 
					    const events = message.submessages.map((obj): {sender_id: number; data: unknown} => ({
 | 
				
			||||||
        sender_id: obj.sender_id,
 | 
					        sender_id: obj.sender_id,
 | 
				
			||||||
        data: JSON.parse(obj.content),
 | 
					        data: JSON.parse(obj.content),
 | 
				
			||||||
    }));
 | 
					    }));
 | 
				
			||||||
@@ -186,7 +186,7 @@ export function handle_event(submsg: Submessage): void {
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let data;
 | 
					    let data: unknown;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        data = JSON.parse(submsg.content);
 | 
					        data = JSON.parse(submsg.content);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user