Unable to access types other than "Storage" (ex. "Bucket") from declaration files #379
Labels
api: storage
Issues related to the googleapis/nodejs-storage API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
🚨
This issue needs some love.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Environment details
@google-cloud/storage
version: 2.0.1Steps to reproduce
google-cloud/storage
.Storage
types likeBucket
by importing them. Ex.import { Bucket } from 'google-cloud/storage';
.Right now, despite multiple declaration files being present in the package's
build
directory, onlyindex.d.ts
is set by thepackage.json
as a declaration file to be made available. Because of this, most of the types are unavailable. The only type I was able to access was theStorage
class (to instantiate a client, etc).Here is an example repo demonstrating the issue. The command
npm build
will fail. The comments marked "compiler error" show idiomatic imports from the library, should the types be made available:https://github.com/welkie/issue-example-ts-google-cloud-storage
Note that the TypeScript documentation on publishing states that the
types
property inpackage.json
should be set to a bundle of declarations: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.htmlAn alternative to adding a build step to concatenate the declaration files into a bundled file would be to export the imported types from the main file. For example:
That way, all types can be imported from the main file like so:
The text was updated successfully, but these errors were encountered: