ms-rest-azure or @azure/cognitiveservices-imagesearch "@azure/cognitiveservices-imagesearch": "^3.0.1",
"ms-rest-azure": "^3.0.0",
Describe the bug
I'm following the documentation at https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/client-libraries?pivots=programming-language-javascript. This doc page says that I should import @azure/cognitiveservices-imagesearch and ms-rest-azure but one of these library seem to either be outdated or isn't compatible with the other. Or the documentation is misleading or outdated?
If you're following the documentation page and you're using TypeScript, you will get the following compiler error:
Argument of type 'CognitiveServicesCredentials' is not assignable to parameter of type 'ServiceClientCredentials'.
Types of property 'signRequest' are incompatible.
Type '(webResource: WebResource, callback: (err: Error) => void) => void' is not assignable to type '(webResource: WebResourceLike) => Promise<WebResourceLike>'.ts(2345)
To Reproduce
Steps to reproduce the behavior:
npm install @azure/cognitiveservices-imagesearch
npm install ms-rest-azure
import {ImageSearchClient} = from '@azure/cognitiveservices-imagesearch'
import {CognitiveServicesCredentials} = from 'ms-rest-azure'
let serviceKey = "My Key";
let searchTerm = "blue salmons";
let credentials = new CognitiveServicesCredentials(serviceKey);
let imageSearchApiClient = new ImageSearchClient(credentials);
// 馃憜 typescript compilation error:
// Argument of type 'CognitiveServicesCredentials' is not assignable to parameter of type 'ServiceClientCredentials'.
// Types of property 'signRequest' are incompatible.
// Type '(webResource: WebResource, callback: (err: Error) => void) => void' is not assignable to type '(webResource: WebResourceLike) => Promise<WebResourceLike>'.
Expected behavior
No compiler error.
Ok, I found a solution. So the documentation is out of date, to make it work I had to use import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js" instead of the library ms-rest-azure.
Thanks for reporting @dgellow!
The workaround you used is indeed correct.
@diberry, @kaerm,
Recently we updated all the docs to use the newer @azure/cognitiveservices-* packages instead of the older azure-cognitiveservices-* packages. While doing so, all usage of ms-rest-azure should have been replaced with @azure/ms-rest-azure-js as well. This package is used to get the CognitiveServicesCredentials required for auth
The QuickStart for ImageSearch is one such case as reported in this issue, am sure there are others. Can we do a sweep of all such docs and do the updates?
@jongio Is this something you are tracking for a fix or something the Cognitive Services team needs to track?
@erhopf FYI
The documentation issue is now resolved and the above page has been updated
Most helpful comment
The documentation issue is now resolved and the above page has been updated