When importing version 2.0.3, TypeScript types are completely messed up:
exists(options: any, callback?: any): void;. The documentation says that it can be used with Promises too (and it works), but the type definition shows return type as void.any as type anywhere. Options dictionaries, callbacks, etc: these are things that should be explicitly typed.Add getFiles to the list. The signature is getFiles(query: GetFilesRequest, callback?: any): void; but the function returns a promise.
Almost all methods have wrong typings. I showed one just as example.
When will the fix be released? I have a project due in a few days and pretty much everything is written in typescript. Is the only solution reverting back to an older version? Or is there another workaround?
@mg131 If it's urgent, you can revert back to using the community-driven @types package.
@welkie Thanks. Will do
@welkie -- How do you override the default index.d.ts provided by the package (other than migrating to 1.7.0)? Also, do you have an ETA on when the types will be fixed?
@rraina Google appears to have disabled the built in types with recent versions of this package until they resolve the issues with them. Therefore, to override them, you'd just opt to use the latest version of of this package with the latest version of the @types package as well. Because I'm not affiliated with Google, I don't know when the issues will be resolved. I'm merely keeping track of their TypeScript efforts so I can reduce the number of dependencies my Node projects have.
Thanks Matt. I tried downloading 2.0.3 (the latest package on NPM at time of this writing) and the @types/google-cloud__storage": "^1.7.2”. However, the 2.0.3 package has a conflicting index.d.ts :/. Let me know if I am doing something wrong.
On Sep 21, 2018, at 1:19 PM, Matt Welke <[email protected]notifications@github.com> wrote:
@rrainahttps://github.com/rraina Google appears to have disabled the built in types with recent versions of this package until they resolve the issues with them. Therefore, to override them, you'd just opt to use the latest version of of this package with the latest version of the @typeshttps://github.com/types package as well. Because I'm not affiliated with Google, I don't know when the issues will be resolved. I'm merely keeping track of their TypeScript efforts so I can reduce the number of dependencies my Node projects have.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/googleapis/nodejs-storage/issues/384#issuecomment-423659233, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABfM1JmtMAH1z8gizO_GqXiZ4Efi3Urzks5udUnfgaJpZM4WkfGP.
@rraina I can't reproduce that issue. I just created a test project (using the tsconfig file from Microsoft's TypeScript-Node-Starter repo) and it compiled properly when I invoked VS Code's default build task: https://github.com/welkie/node-storage-test
Is it possible you have a TypeScript configuration issue?
tried it with the latest [email protected], and has the problem
const isExist = await storage.bucket(CLOUD_STORAGE_BUCKET_NAME || '')
.file(filePath)
.exists(undefined);
and I have this problem error TS1345: An expression of type 'void' cannot be tested for truthiness and when I check the typings, the method returns void...
starting typescript 3.1, they have enforce this, so the older version of typescript might work https://github.com/Microsoft/TypeScript/issues/26262
getFiles() promise is fixed in #402
A released is planned ? Thanks!
@welkie Your repo doesn't have enough code to repro the issue.
Try adding this:
import { Storage } from "@google-cloud/storage";
async function listBuckets() {
const storage = new Storage();
const [buckets] = await storage.getBuckets();
return buckets;
}
First the storage.getBuckets(); call will be an error because of lack of parameters:
$ tsc
src/index.ts:7:29 - error TS2554: Expected 2 arguments, but got 0.
7 const [buckets] = await storage.getBuckets();
~~~~~~~~~~~~~~~~~~~~
So no, it doesn't work to just include the types, because even in your own example, it's finding the local index.d.ts first. So 1.7.2 is _entirely broken_ for TypeScript users.
@TimMensch Yeah I just tested that and I'm getting the same issue. It looks like any non-trivial code example will run into issues since they're currently bundling type declaration files side by side with their source code files:

That's going to be a problem and it looks like people will have to revert to older versions of @google-cloud__storage to a version with no type declaration files bundled at all in order to get to a working state. We won't be updating the package in our TS projects at my work until this is resolved.
Unfortunately, we had to roll back to an earlier 1.x version of cloud storage.
Also, does not seem to be able to import the File type anymore.
Really hope those will get fixed so that we can use the latest.
I must be missing something. It seems that now the 2.x provides it own typing, that take precedence of @types/google-cloud__storage, which is a good step.
However, it feels that now the internal types are vastly different than the original @types/..., which i am not sure it is because the 2.x has a different API or just because the types were written from scratch.
The challenge, is that right now, I am not sure how to use 2.x, since all type check fail?
Anybody else using 2.x with TypeScript ?
We haven't moved to 2.x yet. But I see in the team's 2.1.0 release (https://github.com/googleapis/nodejs-storage/releases/tag/v2.1.0) that they "disable TypeScript as we continue to annotate the project with types". So it sounds like they're completely turning off the d.ts file generation for now. I tried updating my example project to 2.1.0 to test this, but they haven't published 2.1.0 to NPM yet. I'm hoping when they publish it, we can go back to using latest version without TypeScript issues.
Most helpful comment
Almost all methods have wrong typings. I showed one just as example.