From e31c95e32d44d709d96c008cd77d6f6aca60ef40 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Mon, 30 Jan 2023 00:28:30 +0100 Subject: [PATCH] models/chan: don't force existence of constructor properties --- server/models/chan.ts | 55 ++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/server/models/chan.ts b/server/models/chan.ts index 8fd68ed7..65a4067a 100644 --- a/server/models/chan.ts +++ b/server/models/chan.ts @@ -34,19 +34,18 @@ export type FilteredChannel = Chan & { }; class Chan { - // TODO: don't force existence, figure out how to make TS infer it. - id!: number; - messages!: Msg[]; - name!: string; - key!: string; - topic!: string; - firstUnread!: number; - unread!: number; - highlight!: number; - users!: Map; - muted!: boolean; - type!: ChanType; - state!: ChanState; + id: number; + messages: Msg[]; + name: string; + key: string; + topic: string; + firstUnread: number; + unread: number; + highlight: number; + users: Map; + muted: boolean; + type: ChanType; + state: ChanState; userAway?: boolean; special?: SpecialChanType; @@ -56,20 +55,22 @@ class Chan { static optionalProperties = ["userAway", "special", "data", "closed", "num_users"]; constructor(attr?: Partial) { - _.defaults(this, attr, { - id: 0, - messages: [], - name: "", - key: "", - topic: "", - type: ChanType.CHANNEL, - state: ChanState.PARTED, - firstUnread: 0, - unread: 0, - highlight: 0, - users: new Map(), - muted: false, - }); + this.id = 0; + this.messages = []; + this.name = ""; + this.key = ""; + this.topic = ""; + this.type = ChanType.CHANNEL; + this.state = ChanState.PARTED; + this.firstUnread = 0; + this.unread = 0; + this.highlight = 0; + this.users = new Map(); + this.muted = false; + + if (attr) { + Object.assign(this, attr); + } } destroy() {