If you try casting an object which is not a CustomVO, you’ll get null.
I assume you are casting an object from JSON as a VO for type safety.
You can generally turn off as coercions for runtime so it won’t do that
(something I generally do unless I actually want those coercions to save cycles
at runtime). But doing so might cause weird minification issues.
I’d suggest actually converting those objects into proper VOs.
Something like this:
function CustomVO(obj:Object){
this.prop1 = obj.prop1
this.prop2 = obj.prop2
etc...
}
I generally wrap the functionality of converting JSON in some kind of helper
class so as soon as you get notification of a JSON response, it’s already
converted.
HTH,
Harbs
> On Apr 21, 2021, at 2:24 AM, gbarbosa <[email protected]> wrote:
>
> Hi Royale,
>
> I was recently trying to cast an Object
>
> obj as CustomVO
>
> but it would always turn to null. The as operator kept thinking CustomVO was
> type Function() why would this be?
>
> The workaround ending up being to set the prototype.
>
> Object.setPrototypeOf(obj, CustomVO.prototype);
>
> and this successfully casted correctly. Is there a better way to do this?
> Most likely something something to do with the structure of CustomVO? the
> classes it extends?
>
> Thanks for your time.
>
> -Gabriel Barbosa
>
>
>
> --
> Sent from: http://apache-royale-development.20373.n8.nabble.com/