From 2a9fe4677808f51a9d654198afc3c4c01dc2c0b5 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Mon, 18 Apr 2022 11:49:25 -0700 Subject: [PATCH] fix(apps): Properly set the initial value state for isDecorated on models Because the model's isDecorated value is set by static methods before construction, we cannot use the initialization support found in typescript. --- apps/shared/models/base.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/shared/models/base.ts b/apps/shared/models/base.ts index 786a1a161..f2f825c17 100644 --- a/apps/shared/models/base.ts +++ b/apps/shared/models/base.ts @@ -3,14 +3,18 @@ export type Constructor = new (...args: any[]) => T; /** Base class for all models to inherit from. */ export abstract class BaseModel { data!: T; - /** The symbol marker for the function which decorated the model for either app or server. */ - private isDecorated = false; + /** + * Whether the model is decorated, undecorated models will be undefined. + * Because this value is set by the static properties, we cannot initialize a value for it. + * */ + private isDecorated: true | undefined; /** The data as stored in Firestore. */ constructor(data: T) { - if (this.isDecorated === false) { + if (this.isDecorated !== true) { throw Error(); } + this.data = data; this.setData(data); }