ServerMessage.type: string -> number
This commit is contained in:
parent
3fcae4eba1
commit
9fc4e8f80d
1 changed files with 5 additions and 4 deletions
|
@ -1,10 +1,10 @@
|
|||
export enum MessageType {
|
||||
ACK = "0",
|
||||
TEXT = "1",
|
||||
ACK = 0,
|
||||
TEXT = 1,
|
||||
}
|
||||
|
||||
export type ServerMessage = {
|
||||
type: string;
|
||||
type: MessageType;
|
||||
date: number;
|
||||
};
|
||||
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 (
|
||||
!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;
|
||||
}
|
||||
|
|
Reference in a new issue