Safely convert an any object to an object that conforms to an interface

ساخت وبلاگ

Vote count: 0

I would like the proper way to convert an object of type any to an object that conforms to a particular interface, say ApiResponse. The object of type any came from a JSON payload. I would ideally like some proper error handling dealing with this conversion, as well. I have come up with the following approach, but not sure if it's using TypeScript properly or exploiting the best patterns.

asked 6 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 225 تاريخ : چهارشنبه 6 ارديبهشت 1396 ساعت: 6:35