Declare dynamically added class properties in TypeScript
I want to assign properties to the instance of a class without knowing the property names, values and types of values in TypeScript. Lets assume we have the following example.ts script: // This could be a server response and could look totally diffent another time... const someJson:string = '{ "foo": "bar", "bar": "baz" }' class MyClass { someProperty:boolean constructor( json:string ) { const parsedJson:any = JSON.parse( json ) Object.keys( parsedJson ).forEach( ( key:string ) => { this[ key ] = parsedJson[ key ] } ) this['someProperty'] = true } } const myInstance = new MyClass( someJson ) /