The prototype of the class can be dynamically affected to the object:
function cast<T>(obj: any, cl: { new(...args): T }): T {
obj.__proto__ = cl.prototype;
return obj;
}
var john = cast(/* somejson */, Person);
More Related Contents:
- TypeScript: Object.keys return string[]
- Does Typescript support mutually exclusive types?
- How to implement a typescript decorator?
- How to convert a string to number in TypeScript?
- Confusing “duplicate identifier” Typescript error message
- What does the “as const” mean in TypeScript and what is its use case?
- Typescript: Check “typeof” against custom type
- Angular2 – should private variables be accessible in the template?
- Typescript check object by type or interface at runtime with typeguards in 2020+
- How to use fetch in TypeScript
- TypeScript: void return type converted to any type?
- Angular 2 beta.17: Property ‘map’ does not exist on type ‘Observable’
- Default parameters with generics in TypeScript
- Changing Property Name in Typescript Mapped Type
- Unable to import svg files in typescript
- Typescript 2.0. “types” field in tsconfig.json
- is there a way to get all required properties of a typescript object
- What’s the meaning of “=>” in TypeScript? (Fat Arrow)
- How to use array.map with tuples in typescript?
- how to remove properties via mapped type in TypeScript
- “An index signature parameter type cannot be a union type.” – what should I use instead?
- Typescript and spread operator?
- Detailed differences between type annotation `variable: type` and type assertion `expression as type` in TypeScript
- Angular 2 loader on each http request
- Typescript: type narrowing not working for `in` when key is stored in a variable
- Run factory function on import in TypeScript?
- How do I decide whether @types/* goes into `dependencies` or `devDependencies`?
- Self-referencing return type for static methods in inheriting classes
- How to define an interface for objects with dynamic keys?
- Types from both keys and values of object in Typescript