You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With such declaration the data property will be of type any:
Although this is not an issue itself it's not a good practice to return any.
Another inconvenience is that when using the method
the data have to be cast to the expected type
or even left without a type. And this will be a valid syntax since the return type is any
And because of these the code, that uses the method, can potentially throw an runtime error, which could have been avoided if the method was requiring type
The solution is to allow the methods return type to accept generics. If return type is not provided when calling the method then its data property will be of type unknown and any attempt to use some of the data's properties will result an error in the editor:
But if return type is provided then the return data properties are "known" and can be used:
The provided return type will be applied only to the data property of the IHttpReturn interface. The rest of the properties will behave the same (even without specified return type):
The new IHttpReturn definition will be something like:
The text was updated successfully, but these errors were encountered:
At the moment the return type of all methods is
IHttpReturn
. It is defined as:With such declaration the
data
property will be of typeany
:Although this is not an issue itself it's not a good practice to return
any
.Another inconvenience is that when using the method
any
And because of these the code, that uses the method, can potentially throw an runtime error, which could have been avoided if the method was requiring type
The solution is to allow the methods return type to accept
generics
. If return type is not provided when calling the method then itsdata
property will be of typeunknown
and any attempt to use some of the data's properties will result an error in the editor:But if return type is provided then the return data properties are "known" and can be used:
The provided return type will be applied only to the
data
property of theIHttpReturn
interface. The rest of the properties will behave the same (even without specified return type):The new
IHttpReturn
definition will be something like:The text was updated successfully, but these errors were encountered: