fix
This commit is contained in:
parent
b00bf14bb4
commit
16d4e68a8a
@ -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<string, unknown> = {};
|
||||
protected readonly properties: Record<string, string> = {};
|
||||
private _data: Record<string, PersistentType> = {};
|
||||
protected readonly properties: Record<string, PersistentTypeString> = {};
|
||||
|
||||
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<string, unknown> {
|
||||
public to_object (): Record<string, PersistentType> {
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user