From 16d4e68a8a86482dff7a928d95d88679e06512de Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 7 May 2020 18:59:27 +0200 Subject: [PATCH] fix --- lib/Persistent.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Persistent.ts b/lib/Persistent.ts index 697d121..2340b02 100644 --- a/lib/Persistent.ts +++ b/lib/Persistent.ts @@ -1,8 +1,11 @@ import { Assignable, Serializable } from './interfaces'; +type PersistentTypeString = 'string'|'number'|'boolean'; +type PersistentType = string|number|boolean; + export abstract class Persistent implements Assignable, Serializable { - private _data: Record = {}; - protected readonly properties: Record = {}; + private _data: Record = {}; + protected readonly properties: Record = {}; public assign (a: Assignable): void { this.assign_object (a.to_object ()); @@ -16,11 +19,11 @@ export abstract class Persistent implements Assignable, Serializable { for (const key of Object.keys (obj)) { const prop = this.properties[key]; if (typeof prop !== 'undefined' && typeof obj[key] === prop) - this._data[key] = obj[key]; + this._data[key] = obj[key] as PersistentType; } } - public to_object (): Record { + public to_object (): Record { return this._data; } @@ -33,10 +36,10 @@ export abstract class Persistent implements Assignable, Serializable { public set (key: string, value: unknown): void { const prop = this.properties[key]; if (typeof prop !== 'undefined' && typeof value === prop) - this._data[key] = value; + this._data[key] = value as PersistentType; } - public get (key: string): unknown { + public get (key: string): PersistentType { return this._data[key]; } }