fix
This commit is contained in:
		@@ -1,8 +1,11 @@
 | 
				
			|||||||
import { Assignable, Serializable } from './interfaces';
 | 
					import { Assignable, Serializable } from './interfaces';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PersistentTypeString = 'string'|'number'|'boolean';
 | 
				
			||||||
 | 
					type PersistentType = string|number|boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export abstract class Persistent implements Assignable, Serializable {
 | 
					export abstract class Persistent implements Assignable, Serializable {
 | 
				
			||||||
  private _data: Record<string, unknown> = {};
 | 
					  private _data: Record<string, PersistentType> = {};
 | 
				
			||||||
  protected readonly properties: Record<string, string> = {};
 | 
					  protected readonly properties: Record<string, PersistentTypeString> = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public assign (a: Assignable): void {
 | 
					  public assign (a: Assignable): void {
 | 
				
			||||||
    this.assign_object (a.to_object ());
 | 
					    this.assign_object (a.to_object ());
 | 
				
			||||||
@@ -16,11 +19,11 @@ export abstract class Persistent implements Assignable, Serializable {
 | 
				
			|||||||
    for (const key of Object.keys (obj)) {
 | 
					    for (const key of Object.keys (obj)) {
 | 
				
			||||||
      const prop = this.properties[key];
 | 
					      const prop = this.properties[key];
 | 
				
			||||||
      if (typeof prop !== 'undefined' && typeof obj[key] === prop)
 | 
					      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;
 | 
					    return this._data;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,10 +36,10 @@ export abstract class Persistent implements Assignable, Serializable {
 | 
				
			|||||||
  public set (key: string, value: unknown): void {
 | 
					  public set (key: string, value: unknown): void {
 | 
				
			||||||
    const prop = this.properties[key];
 | 
					    const prop = this.properties[key];
 | 
				
			||||||
    if (typeof prop !== 'undefined' && typeof value === prop)
 | 
					    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];
 | 
					    return this._data[key];
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user