Casting
Cast (Aka. clone) allow to cast any object to class instance
Cast allows to transform any object to class instance with all of the class functionalities including static methods and properties.
Usage
Interface
cast(classType, data, applyConstructor:boolean = false)
classInstance
- The typeof class we want to cast to.data
- The data should be cast.applyConstructor
- identify if constructor method should apply (default isfalse
)
Using cast can be done in two ways:
Without applying the class constructor
In that case the data will cast into class instance but constructor method will not apply, which means auto populated properties won't initialize.
Example
post.class.ts
main.ts
With applying the class constructor
In that case the data will cast into class instance and constructor method will apply, which means auto populated properties will initialize.
Example
post.class.ts
main.ts
Last updated