From d6b22844f636d160c4c335f5376096fbe942f1f4 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Fri, 27 Aug 2021 07:52:57 +0900 Subject: [PATCH] Update code to make it TS 4.4 compatible --- packages/oauth/package.json | 4 ++-- packages/oauth/src/index.ts | 4 ++-- packages/rtm-api/src/KeepAlive.ts | 2 +- packages/rtm-api/src/RTMClient.ts | 2 +- packages/socket-mode/src/SocketModeClient.ts | 2 +- packages/web-api/src/WebClient.ts | 10 ++++++---- .../test/types/webclient-paginate-types.test-d.ts | 3 ++- packages/webhook/src/IncomingWebhook.ts | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/oauth/package.json b/packages/oauth/package.json index 598fe046a..ad8dfef33 100644 --- a/packages/oauth/package.json +++ b/packages/oauth/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "@slack/logger": "^3.0.0", - "@slack/web-api": "^6.0.0", + "@slack/web-api": "^6.3.0", "@types/jsonwebtoken": "^8.3.7", "@types/node": ">=12", "jsonwebtoken": "^8.5.1", @@ -64,4 +64,4 @@ "typescript": "^4.1", "uncaughtException": "^1.0.0" } -} \ No newline at end of file +} diff --git a/packages/oauth/src/index.ts b/packages/oauth/src/index.ts index 1ed36bfa8..1e70767c3 100644 --- a/packages/oauth/src/index.ts +++ b/packages/oauth/src/index.ts @@ -191,7 +191,7 @@ export class InstallProvider { } return authResult; - } catch (error) { + } catch (error: any) { throw new AuthorizationError(error.message); } } @@ -453,7 +453,7 @@ export class InstallProvider { this.logger.debug('run built-in success function'); callbackSuccess(installation, installOptions, req, res); } - } catch (error) { + } catch (error: any) { this.logger.error(error); // Call the failure callback diff --git a/packages/rtm-api/src/KeepAlive.ts b/packages/rtm-api/src/KeepAlive.ts index 54ff03044..1be9aa015 100644 --- a/packages/rtm-api/src/KeepAlive.ts +++ b/packages/rtm-api/src/KeepAlive.ts @@ -217,7 +217,7 @@ export class KeepAlive extends EventEmitter { .catch((error) => { this.logger.error(`Unhandled error: ${error.message}. Please report to @slack/rtm-api package maintainers.`); }); - } catch (error) { + } catch (error: any) { this.logger.error(`Unhandled error: ${error.message}. Please report to @slack/rtm-api package maintainers.`); } } diff --git a/packages/rtm-api/src/RTMClient.ts b/packages/rtm-api/src/RTMClient.ts index a2e502729..db2ddb05c 100644 --- a/packages/rtm-api/src/RTMClient.ts +++ b/packages/rtm-api/src/RTMClient.ts @@ -596,7 +596,7 @@ export class RTMClient extends EventEmitter { let event; try { event = JSON.parse(data); - } catch (parseError) { + } catch (parseError: any) { // prevent application from crashing on a bad message, but log an error to bring attention this.logger.error( `unable to parse incoming websocket message: ${parseError.message}\n message contents: "${data}"`, diff --git a/packages/socket-mode/src/SocketModeClient.ts b/packages/socket-mode/src/SocketModeClient.ts index 8cbec9af0..e4d56cdf4 100644 --- a/packages/socket-mode/src/SocketModeClient.ts +++ b/packages/socket-mode/src/SocketModeClient.ts @@ -542,7 +542,7 @@ export class SocketModeClient extends EventEmitter { try { event = JSON.parse(data); - } catch (parseError) { + } catch (parseError: any) { // prevent application from crashing on a bad message, but log an error to bring attention this.logger.error( `unable to parse incoming websocket message: ${parseError.message}`, diff --git a/packages/web-api/src/WebClient.ts b/packages/web-api/src/WebClient.ts index d63e09c96..e9f34a935 100644 --- a/packages/web-api/src/WebClient.ts +++ b/packages/web-api/src/WebClient.ts @@ -359,9 +359,11 @@ export class WebClient extends Methods { return response; } catch (error) { - this.logger.warn('http request failed', error.message); - if (error.request) { - throw requestErrorWithOriginal(error); + // To make this compatible with tsd, casting here instead of `catch (error: any)` + const e = error as any; + this.logger.warn('http request failed', e.message); + if (e.request) { + throw requestErrorWithOriginal(e); } throw error; } @@ -571,7 +573,7 @@ function paginationOptionsForNextPage( cursor: previousResult.response_metadata.next_cursor as string, }; } - return; + return undefined; } /** diff --git a/packages/web-api/test/types/webclient-paginate-types.test-d.ts b/packages/web-api/test/types/webclient-paginate-types.test-d.ts index 27783d628..94c82eedf 100644 --- a/packages/web-api/test/types/webclient-paginate-types.test-d.ts +++ b/packages/web-api/test/types/webclient-paginate-types.test-d.ts @@ -17,9 +17,10 @@ expectError(web.paginate('conversations.list', {}, () => 7)); expectType>(web.paginate('conversations.list', {}, () => false, () => 5)); +// NOTE: this error does not arise with TypeScript 4.4+ // When there's no shouldStop predicate given but there is a reducer, the behavior is undefined. // (However in the current implementation, the return value is `AsyncIteratable`.) -expectError(web.paginate('conversations.list', {}, undefined, () => 5)); +// expectError(web.paginate('conversations.list', {}, undefined, () => 5)); // Ensure that it works in a for-await-of loop. async () => { diff --git a/packages/webhook/src/IncomingWebhook.ts b/packages/webhook/src/IncomingWebhook.ts index 0b1cb42c1..4a5b693f7 100644 --- a/packages/webhook/src/IncomingWebhook.ts +++ b/packages/webhook/src/IncomingWebhook.ts @@ -62,7 +62,7 @@ export class IncomingWebhook { try { const response = await this.axios.post(this.url, payload); return this.buildResult(response); - } catch (error) { + } catch (error: any) { // Wrap errors in this packages own error types (abstract the implementation details' types) if (error.response !== undefined) { throw httpErrorWithOriginal(error);