Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 5b34888

Browse files
Improve types (#381)
1 parent b1cfa1a commit 5b34888

5 files changed

Lines changed: 96 additions & 56 deletions

File tree

src/bucket.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class Bucket extends ServiceObject {
299299
*/
300300
getFilesStream: Function;
301301

302-
constructor(storage, name, options?) {
302+
constructor(storage: Storage, name: string, options?) {
303303
options = options || {};
304304

305305
// Allow for "gs://"-style input, and strip any trailing slashes.
@@ -422,7 +422,7 @@ class Bucket extends ServiceObject {
422422
* const apiResponse = data[1];
423423
* });
424424
*/
425-
combine(sources, destination, options, callback) {
425+
combine(sources: string[]|File[], destination, options, callback) {
426426
if (!is.array(sources) || sources.length < 2) {
427427
throw new Error('You must provide at least two source files.');
428428
}
@@ -436,15 +436,15 @@ class Bucket extends ServiceObject {
436436
options = {};
437437
}
438438

439-
const convertToFile = file => {
439+
const convertToFile = (file: string|File) => {
440440
if (file instanceof File) {
441441
return file;
442442
}
443-
444443
return this.file(file);
445444
};
446445

447-
sources = sources.map(convertToFile);
446+
// tslint:disable-next-line:no-any
447+
sources = (sources as any).map(convertToFile);
448448
destination = convertToFile(destination);
449449
callback = callback || util.noop;
450450

@@ -465,7 +465,8 @@ class Bucket extends ServiceObject {
465465
destination: {
466466
contentType: destination.metadata.contentType,
467467
},
468-
sourceObjects: sources.map(source => {
468+
// tslint:disable-next-line:no-any
469+
sourceObjects: (sources as any).map(source => {
469470
const sourceObject = {
470471
name: source.name,
471472
} as SourceObject;
@@ -544,7 +545,7 @@ class Bucket extends ServiceObject {
544545
* const apiResponse = data[1];
545546
* });
546547
*/
547-
createChannel(id, config, options, callback) {
548+
createChannel(id: string, config, options, callback?) {
548549
if (!is.string(id)) {
549550
throw new Error('An ID is required to create a channel.');
550551
}
@@ -671,14 +672,15 @@ class Bucket extends ServiceObject {
671672
* region_tag:storage_create_notification
672673
* Another example:
673674
*/
674-
createNotification(topic, options, callback) {
675+
createNotification(topic: string, options, callback?) {
675676
if (is.fn(options)) {
676677
callback = options;
677678
options = {};
678679
}
679680

680681
if (is.object(topic) && util.isCustomType(topic, 'pubsub/topic')) {
681-
topic = topic.name;
682+
// tslint:disable-next-line:no-any
683+
topic = (topic as any).name;
682684
}
683685

684686
if (!is.string(topic)) {
@@ -849,7 +851,7 @@ class Bucket extends ServiceObject {
849851
* //-
850852
* bucket.deleteFiles().then(function() {});
851853
*/
852-
deleteFiles(query: DeleteFilesRequest, callback) {
854+
deleteFiles(query: DeleteFilesRequest, callback?) {
853855
if (is.fn(query)) {
854856
callback = query;
855857
query = {};
@@ -942,7 +944,7 @@ class Bucket extends ServiceObject {
942944
* const apiResponse = data[0];
943945
* });
944946
*/
945-
deleteLabels(labels, callback?) {
947+
deleteLabels(labels: string|string[], callback?) {
946948
if (is.fn(labels)) {
947949
callback = labels;
948950
labels = [];
@@ -1017,7 +1019,7 @@ class Bucket extends ServiceObject {
10171019
* region_tag:storage_disable_requester_pays
10181020
* Example of disabling requester pays:
10191021
*/
1020-
disableRequesterPays(callback) {
1022+
disableRequesterPays(callback?) {
10211023
this.setMetadata(
10221024
{
10231025
billing: {
@@ -1161,7 +1163,7 @@ class Bucket extends ServiceObject {
11611163
* const bucket = storage.bucket('albums');
11621164
* const file = bucket.file('my-existing-file.png');
11631165
*/
1164-
file(name, options?: FileOptions) {
1166+
file(name: string, options?: FileOptions) {
11651167
if (!name) {
11661168
throw Error('A file name must be specified.');
11671169
}
@@ -1559,7 +1561,7 @@ class Bucket extends ServiceObject {
15591561
* region_tag:storage_list_notifications
15601562
* Another example:
15611563
*/
1562-
getNotifications(options, callback) {
1564+
getNotifications(options, callback?) {
15631565
if (is.fn(options)) {
15641566
callback = options;
15651567
options = {};
@@ -1672,7 +1674,7 @@ class Bucket extends ServiceObject {
16721674
* const files = data[0];
16731675
* });
16741676
*/
1675-
makePrivate(options, callback) {
1677+
makePrivate(options, callback?) {
16761678
if (is.fn(options)) {
16771679
callback = options;
16781680
options = {};
@@ -1795,7 +1797,7 @@ class Bucket extends ServiceObject {
17951797
* const files = data[0];
17961798
* });
17971799
*/
1798-
makePublic(options, callback) {
1800+
makePublic(options, callback?) {
17991801
if (is.fn(options)) {
18001802
callback = options;
18011803
options = {};
@@ -1850,7 +1852,7 @@ class Bucket extends ServiceObject {
18501852
* const bucket = storage.bucket('my-bucket');
18511853
* const notification = bucket.notification('1');
18521854
*/
1853-
notification(id) {
1855+
notification(id: string) {
18541856
if (!id) {
18551857
throw new Error('You must supply a notification ID.');
18561858
}
@@ -2084,7 +2086,7 @@ class Bucket extends ServiceObject {
20842086
*
20852087
* bucket.setUserProject('grape-spaceship-123');
20862088
*/
2087-
setUserProject(userProject) {
2089+
setUserProject(userProject: string) {
20882090
this.userProject = userProject;
20892091
}
20902092

@@ -2290,7 +2292,7 @@ class Bucket extends ServiceObject {
22902292
* region_tag:storage_upload_encrypted_file
22912293
* Example of uploading an encrypted file:
22922294
*/
2293-
upload(pathString, options, callback) {
2295+
upload(pathString: string, options, callback?) {
22942296
if (global['GCLOUD_SANDBOX_ENV']) {
22952297
return;
22962298
}

src/channel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import {ServiceObject, util} from '@google-cloud/common';
2020
import {promisifyAll} from '@google-cloud/promisify';
2121
import * as request from 'request';
22+
import {Storage} from '.';
2223

2324
/**
2425
* Create a channel object to interact with a Cloud Storage channel.
@@ -36,7 +37,7 @@ import * as request from 'request';
3637
* const channel = storage.channel('id', 'resource-id');
3738
*/
3839
class Channel extends ServiceObject {
39-
constructor(storage, id, resourceId) {
40+
constructor(storage: Storage, id: string, resourceId: string) {
4041
const config = {
4142
parent: storage,
4243
baseUrl: '/channels',
@@ -93,7 +94,7 @@ class Channel extends ServiceObject {
9394
* const apiResponse = data[0];
9495
* });
9596
*/
96-
stop(callback) {
97+
stop(callback?) {
9798
callback = callback || util.noop;
9899

99100
this.request(

0 commit comments

Comments
 (0)