angular - Convert WabApi response array to typed array -


i have webapi returns array like:

[  {"id":1,"name": "name" } ] 

when doing get

http.get<mytype[]>('url') .subscribe(data => {   // data = [object] }) 

the data not getting converted in object. stays [object]. can access data data[0].id, data[0].name official httpclient doc saying can typecheck data fine. how convert whole array in type in case mytype[] ?

i using angular 4.3+ httpclient

i'm assuming question:

do have access data data[0].id, data[0].name ?

yes have, because data array.

besides, said:...

the data not getting converted in object. stays [object]... ideas how convert response in mytype[] ?

i'm not sure understand type system is. typescript type system. plays no role in runtime. time compile typescript (which have in order run it), there's no typescript anymore. if see typescript in runtime, that's representation can make sense of code. called source-maps. in runtime, it's javascript.

that being said, there're no objects being converted 1 type other in runtime. conversion exists (foo any).bar()), again, exists until compile type system can know foo has bar().

your response should mytype[]. if see [object] in runtime, that's because chrome dev tools calling tostring() on mytype, hasn't been overriden, display [object].


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -