I'm writing clone
method for a Config
class:
abstract class ParentConfig {
id: string | undefined;
name: string = '';
}
export class Config extends ParentConfig {
version: number | undefined;
constructor() {
super();
}
clone = (): Config => {
const config = new Config();
Object.assign(config, JSON.parse(JSON.stringify(this))); // this.version is undefined!!!
return config;
}
}
const firstConfig = new Config();
firstConfig.name = 'first';
firstConfig.version = 1;
const secondConfig = firstConfig.clone();
secondConfig.version;// undefined
Before calling clone
, I can see in the Dev tool that Config
instance has a proper version
but new returned Config
has undefined version.
Any ideas?