Seeking guidance on converting the Javascript code below to TypeScript:
var storage = require('@google-cloud/storage')();
var myBucket = storage.bucket('my-bucket');
var file = myBucket.file('my-file');
file.makePublic(function(err, apiResponse) {});
I attempted the conversion as follows:
import * as storage from '@google-cloud/storage';
const myBucket = storage.Bucket('my-bucket');
const file = myBucket.file('my-file');
file.makePublic(function(err, apiResponse) {});
However, Visual Studio Code is flagging this line (highlighted in bold):
const myBucket = storage.Bucket('my-bucket');
Hovering over the underlined line reveals the following message:
[ts] Value of type 'typeof Bucket' is not callable. Did you mean to include 'new'? class Storage.Bucket
It seems like I need to instantiate the class using the new keyword, but even after making that change, the line remains flagged by Visual Studio Code (bold):
const myBucket = new storage.Bucket('my-bucket');
This time, the error message states:
[ts] Expected 2 arguments, but got 1. constructor Storage.Bucket(storage: storage.Storage, name: string): storage.Bucket
This indicates that two arguments are required - one of type storage and one of type string. While I have the second argument (string type), I am unsure how to create the storage type.
How can I define the first argument (storage type)?
In the original Javascript example, only the second argument (string type) is needed. The Javascript code seems to somehow infer or provide a default value for the storage type. Is there a way to achieve the same in the TypeScript version?
Thank you for your assistance.