typescript - How to type JSON results -
i convert js ts:
class foo{ getsection() { return dataservice.getsection('home_page').then(data => { this.section(data.results[0]); //error here }); } }
the compile time error message is: property 'results' not exist on type 'void'.
data
json result set, , results[0]
simple first record.
how type resolve error?
the issue dataservice.getsection('home_page')
being inferred return promise<void>
, therefore data
of type void
.
fix in dataservice
:
getsection(secname: string): promise<any>
or stronger if don't want any
.
(some basic docs on annotations : http://basarat.gitbooks.io/typescript/content/docs/types/type-system.html)
Comments
Post a Comment