Say I have the following class:
export class MyClass {
str: string = '';
foo() {
console.log(this.str);
}
}
Then, in some other code:
var myObj = {
str: 'Hello World';
}
How can I convert myObj into a MyClass instance, so the following line works:
myObj.foo();
// writes 'Hello World' to the console
(Please note that I cannot change the creation of myObj, because it's created in another library)
***** EDIT: *****
I'm still looking for a solution for this. The main problem is that MyClass has references to other classes, which maybe have references to MyClass. It's a whole object graph that I'm trying to convert to TypeScript classes.
Of every class and every property I know its type, and it matches perfectly with the classes and properties defined on MyClass.