nodejs-compute icon indicating copy to clipboard operation
nodejs-compute copied to clipboard

Incorrect TypeScript definitions

Open cmdshepard opened this issue 2 years ago • 2 comments

Environment details

  • OS: macOS 12.4
  • Node.js version: 16.15.0
  • npm version: 8.14.0
  • @google-cloud/compute version: 3.4.0

Steps to reproduce

In a TypeScript project, create an AddressesClient, use the #insert method and attempt to read the status of operation.latestResponse. TypeScript compilation will fail.

import { AddressesClient } from "@google-cloud/compute";

const main = async () => {
  const addressesClient = new AddressesClient();
  const [operation] = await addressesClient.insert({ /* payload */ });
  
  console.log(operation.latestResponse.status); // Complier Error: Property 'status' does not exist on type 'Operation'.
};

main()
  .catch(console.error)
  .finally(process.exit);

It looks like the latestResponse is typed to to the google.longrunning.Operation class. However upon inspection of the object in the debugger, latestResponse is of type:

warnings: Array
id: String
kind: String
name: String
user: String
startTime: String
targetLink: String
progress: Number
region: String
operationType: String
status: String
targetId: String
clientOperationId: String
insertTime: String
selfLink: String

Thank you in advance!

cmdshepard avatar Jul 17 '22 06:07 cmdshepard

Thank you for the report @cmdshepard. We are working for the full support for long running operations in the Compute client, I'm expecting to release the changes within a week or two, which should fix this issue as well (and make the await operation.promise() actually work, because it does not work properly now).

alexander-fenster avatar Jul 20 '22 22:07 alexander-fenster

Also reporting the same issue, seems the library is unusable with TypeScript unless you use any, not good.

ollyde avatar Aug 12 '22 08:08 ollyde