Azure-sdk-for-js: @azure/cognitiveservices-imagesearch not compatible with ms-rest-azure

Created on 9 Sep 2020  路  4Comments  路  Source: Azure/azure-sdk-for-js

  • Package Name: either ms-rest-azure or @azure/cognitiveservices-imagesearch
  • Package Version:
    "@azure/cognitiveservices-imagesearch": "^3.0.1",
    "ms-rest-azure": "^3.0.0",
  • Operating system: Windows 10
  • [ ] nodejs

    • version: Not relevant

  • [ ] typescript

    • version: Not relevant

  • Is the bug related to documentation in

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:

  1. Go to https://docs.microsoft.com/en-us/azure/cognitive-services/bing-image-search/quickstarts/client-libraries?pivots=programming-language-javascript
  2. Install dependencies as documented:
npm install @azure/cognitiveservices-imagesearch
npm install ms-rest-azure
  1. Import libraries:
import {ImageSearchClient} = from '@azure/cognitiveservices-imagesearch'
import {CognitiveServicesCredentials} = from 'ms-rest-azure'
  1. Try to create the search client, as documented:
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.

Client Cognitive Services Docs bug customer-reported

Most helpful comment

The documentation issue is now resolved and the above page has been updated

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings