ServerMessage.type: string -> number

This commit is contained in:
Tobias Berger 2022-01-07 18:28:34 +01:00
parent 3fcae4eba1
commit 9fc4e8f80d

View file

@ -1,10 +1,10 @@
export enum MessageType { export enum MessageType {
ACK = "0", ACK = 0,
TEXT = "1", TEXT = 1,
} }
export type ServerMessage = { export type ServerMessage = {
type: string; type: MessageType;
date: number; date: number;
}; };
export function isServerMessage(obj: unknown): obj is ServerMessage { export function isServerMessage(obj: unknown): obj is ServerMessage {
@ -12,7 +12,8 @@ export function isServerMessage(obj: unknown): obj is ServerMessage {
if (obj === null) return false; if (obj === null) return false;
if ( if (
!Object.hasOwnProperty.call(obj, "type") || !Object.hasOwnProperty.call(obj, "type") ||
typeof (obj as { type: unknown }).type !== "string" typeof (obj as { type: unknown }).type !== "number" ||
!Object.hasOwnProperty.call(MessageType, (obj as { type: number }).type)
) { ) {
return false; return false;
} }