Recently, I have started using Typescript and there's something I am uncertain about.
I am utilizing an npm package called azure-storage
and specifically invoking a method called doesBlobExist
:
blobService.doesBlobExist(containerName, blobName, (callbackResult: ErrorOrResult<BlobService.BlobResult>) => {
// Want callbackResult.response here
});
The doesBlobExist
function (which comes from the npm package) looks like this:
doesBlobExist(container: string, blob: string, callback: ErrorOrResult<BlobService.BlobResult>): void;
Additionally, the ErrorOrResult type is an interface with the following structure:
interface ErrorOrResult<TResult> {
(error: Error, result: TResult, response: ServiceResponse): void
}
My uncertainty lies in the fact that when I call the function, I thought I could utilize the interface like this:
callbackResult.response
since it is defined in the interface. However, I keep getting null
when accessing callbackResult
. Upon investigating, I found that it is being set as the error: Error
from the interface.
Therefore, I am wondering if it is feasible to achieve what I desire above, or if I need to use the function in this manner:
blobService.doesBlobExist(containerName, blobName, (error, result, response) => {
// specify the 3 items directly in the interface
});